Skip to content

Commit

Permalink
qa: minor style changes and refactors
Browse files Browse the repository at this point in the history
- multi-line ternaries should have each element start on a line of its
  own.
- pass the connection timeout value to `setupSocket()` (in case the
  constant is not defined)
- consistency in annotation spacing and definition

Signed-off-by: Matthew Weier O'Phinney <[email protected]>
  • Loading branch information
weierophinney committed Jul 28, 2020
1 parent 5c66122 commit f5b8b0a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/Protocol/Imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace Laminas\Mail\Protocol;

use Laminas\Stdlib\ErrorHandler;

class Imap
{
use ProtocolTrait;
Expand Down Expand Up @@ -84,7 +82,7 @@ public function connect($host, $port = null, $ssl = false)
}
}

$this->setupSocket($host, $port);
$this->setupSocket($host, $port, self::TIMEOUT_CONNECTION);

if (! $this->assumedNextLine('* OK')) {
throw new Exception\RuntimeException('host doesn\'t allow connection');
Expand Down
2 changes: 1 addition & 1 deletion src/Protocol/Pop3.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function connect($host, $port = null, $ssl = false)
}
}

$this->setupSocket($host, $port);
$this->setupSocket($host, $port, self::TIMEOUT_CONNECTION);

$welcome = $this->readResponse();

Expand Down
17 changes: 10 additions & 7 deletions src/Protocol/ProtocolTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Laminas\Mail\Protocol;

use Laminas\Stdlib\ErrorHandler;

/**
* https://bugs.php.net/bug.php?id=69195
*/
Expand Down Expand Up @@ -37,9 +39,8 @@ public function getCryptoMethod()
/**
* Do not validate SSL certificate
*
* @param bool $novalidatecert Set to true to disable certificate validation
*
* @return Imap|Pop3
* @param bool $novalidatecert Set to true to disable certificate validation
* @return self
*/
public function setNoValidateCert(bool $novalidatecert)
{
Expand Down Expand Up @@ -70,25 +71,27 @@ private function prepareSocketOptions()
'verify_peer_name' => false,
'verify_peer' => false,
]
] : [];
]
: [];
}

/**
* Setup connection socket
*
* @param string $host hostname or IP address of IMAP server
* @param int|null $port of IMAP server, default is 143 (993 for ssl)
*
* @param int $timeout timeout in seconds for initiating session
* @return void
* @throws Exception\RuntimeException If unable to connect to host.
*/
protected function setupSocket($host, $port)
protected function setupSocket($host, $port, $timeout)
{
ErrorHandler::start();
$this->socket = stream_socket_client(
$host . ":" . $port,
$errno,
$errstr,
self::TIMEOUT_CONNECTION,
$timeout,
STREAM_CLIENT_CONNECT,
stream_context_create($this->prepareSocketOptions())
);
Expand Down

0 comments on commit f5b8b0a

Please sign in to comment.