Skip to content

Commit

Permalink
Merge pull request #109 from glensc/codestyle
Browse files Browse the repository at this point in the history
Code style fixes in tests
  • Loading branch information
Ocramius committed Jan 12, 2021
2 parents 0c4c9c2 + f0eea2a commit c1f2125
Show file tree
Hide file tree
Showing 74 changed files with 965 additions and 1,012 deletions.
2 changes: 1 addition & 1 deletion src/AddressList.php
Expand Up @@ -105,7 +105,7 @@ public function addFromString($address, $comment = null)
* @param AddressList $addressList
* @return AddressList
*/
public function merge(AddressList $addressList)
public function merge(self $addressList)
{
foreach ($addressList as $address) {
$this->add($address);
Expand Down
4 changes: 2 additions & 2 deletions src/Header/ContentDisposition.php
Expand Up @@ -18,7 +18,7 @@ class ContentDisposition implements UnstructuredInterface
*
* @var int
*/
const MAX_PARAMETER_LENGTH = 76;
public const MAX_PARAMETER_LENGTH = 76;

/**
* @var string
Expand Down Expand Up @@ -79,7 +79,7 @@ public static function fromString($headerLine)

foreach ($continuedValues as $name => $values) {
$value = '';
for ($i = 0; $i < count($values); $i++) {
for ($i = 0, $iMax = count($values); $i < $iMax; $i++) {
if (! isset($values[$i])) {
throw new Exception\InvalidArgumentException(
'Invalid header line for Content-Disposition string - incomplete continuation'
Expand Down
3 changes: 2 additions & 1 deletion src/Header/ContentType.php
Expand Up @@ -181,7 +181,8 @@ public function getParameter($name)
if (isset($this->parameters[$name])) {
return $this->parameters[$name];
}
return;

return null;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Header/HeaderInterface.php
Expand Up @@ -15,14 +15,14 @@ interface HeaderInterface
*
* @var bool
*/
const FORMAT_ENCODED = true;
public const FORMAT_ENCODED = true;

/**
* Return value in internal encoding which is usually UTF-8
*
* @var bool
*/
const FORMAT_RAW = false;
public const FORMAT_RAW = false;

/**
* Factory to generate a header object from a string
Expand All @@ -47,7 +47,7 @@ public function getFieldName();
* @param bool $format Return the value in Mime::Encoded or in Raw format
* @return string
*/
public function getFieldValue($format = HeaderInterface::FORMAT_RAW);
public function getFieldValue($format = self::FORMAT_RAW);

/**
* Set header encoding
Expand Down
2 changes: 1 addition & 1 deletion src/Header/HeaderLocator.php
Expand Up @@ -50,7 +50,7 @@ final class HeaderLocator implements HeaderLocatorInterface
public function get(string $name, ?string $default = null): ?string
{
$name = $this->normalizeName($name);
return isset($this->plugins[$name]) ? $this->plugins[$name] : $default;
return $this->plugins[$name] ?? $default;
}

public function has(string $name): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Header/IdentificationField.php
Expand Up @@ -47,7 +47,7 @@ public static function fromString($headerLine)
$value = HeaderWrap::mimeDecodeValue($value);

$messageIds = array_map(
[IdentificationField::class, "trimMessageId"],
[self::class, "trimMessageId"],
explode(" ", $value)
);

Expand Down Expand Up @@ -127,7 +127,7 @@ public function setIds($ids)
}
}

$this->messageIds = array_map([IdentificationField::class, "trimMessageId"], $ids);
$this->messageIds = array_map([self::class, "trimMessageId"], $ids);
return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Header/ListParser.php
Expand Up @@ -15,9 +15,9 @@
*/
class ListParser
{
const CHAR_QUOTES = ['\'', '"'];
const CHAR_DELIMS = [',', ';'];
const CHAR_ESCAPE = '\\';
public const CHAR_QUOTES = ['\'', '"'];
public const CHAR_DELIMS = [',', ';'];
public const CHAR_ESCAPE = '\\';

/**
* @param string $value
Expand Down
2 changes: 1 addition & 1 deletion src/Header/Received.php
Expand Up @@ -80,7 +80,7 @@ public function toStringMultipleHeaders(array $headers)
{
$strings = [$this->toString()];
foreach ($headers as $header) {
if (! $header instanceof Received) {
if (! $header instanceof self) {
throw new Exception\RuntimeException(
'The Received multiple header implementation can only accept an array of Received headers'
);
Expand Down
11 changes: 4 additions & 7 deletions src/Headers.php
Expand Up @@ -13,7 +13,6 @@
use ArrayIterator;
use Countable;
use Iterator;
use Laminas\Loader\PluginClassLoader;
use Laminas\Loader\PluginClassLocator;
use Laminas\Mail\Header\GenericHeader;
use Laminas\Mail\Header\HeaderInterface;
Expand All @@ -27,10 +26,10 @@
class Headers implements Countable, Iterator
{
/** @var string End of Line for fields */
const EOL = "\r\n";
public const EOL = "\r\n";

/** @var string Start of Line when folding */
const FOLDING = "\r\n ";
public const FOLDING = "\r\n ";

/**
* @var null|Header\HeaderLocatorInterface
Expand Down Expand Up @@ -391,10 +390,8 @@ public function get($name)
case 1:
if ($results[0] instanceof Header\MultipleHeadersInterface) {
return new ArrayIterator($results);
} else {
return $results[0];
}
//fall-trough
return $results[0];
default:
return new ArrayIterator($results);
}
Expand Down Expand Up @@ -541,7 +538,7 @@ public function forceLoading()
*/
public function loadHeader($headerLine)
{
list($name, ) = Header\GenericHeader::splitHeaderLine($headerLine);
list($name) = Header\GenericHeader::splitHeaderLine($headerLine);

/** @var HeaderInterface $class */
$class = $this->resolveHeaderClass($name);
Expand Down
4 changes: 2 additions & 2 deletions src/Protocol/AbstractProtocol.php
Expand Up @@ -21,12 +21,12 @@ abstract class AbstractProtocol
/**
* Mail default EOL string
*/
const EOL = "\r\n";
public const EOL = "\r\n";

/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
public const TIMEOUT_CONNECTION = 30;

/**
* Maximum of the transaction log
Expand Down
9 changes: 5 additions & 4 deletions src/Protocol/Imap.php
Expand Up @@ -15,7 +15,7 @@ class Imap
/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
public const TIMEOUT_CONNECTION = 30;

/**
* @var null|resource
Expand Down Expand Up @@ -290,13 +290,13 @@ public function readResponse($tag, $dontParse = false)
// last to chars are still needed for response code
$tokens = [substr($tokens, 0, 2)];
}

// last line has response code
if ($tokens[0] == 'OK') {
return $lines ? $lines : true;
} elseif ($tokens[0] == 'NO') {
return false;
}
return;
}

/**
Expand Down Expand Up @@ -364,10 +364,11 @@ public function escapeString($string)
if (func_num_args() < 2) {
if (strpos($string, "\n") !== false) {
return ['{' . strlen($string) . '}', $string];
} else {
return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"';
}

return '"' . str_replace(['\\', '"'], ['\\\\', '\\"'], $string) . '"';
}

$result = [];
foreach (func_get_args() as $string) {
$result[] = $this->escapeString($string);
Expand Down
16 changes: 5 additions & 11 deletions src/Protocol/Pop3.php
Expand Up @@ -17,7 +17,7 @@ class Pop3
/**
* Default timeout in seconds for initiating session
*/
const TIMEOUT_CONNECTION = 30;
public const TIMEOUT_CONNECTION = 30;

/**
* saves if server supports top
Expand Down Expand Up @@ -127,7 +127,7 @@ public function connect($host, $port = null, $ssl = false)
public function sendRequest($request)
{
ErrorHandler::start();
$result = fputs($this->socket, $request . "\r\n");
$result = fwrite($this->socket, $request . "\r\n");
$error = ErrorHandler::stop();
if (! $result) {
throw new Exception\RuntimeException('send failed - connection closed?', 0, $error);
Expand Down Expand Up @@ -171,7 +171,7 @@ public function readResponse($multiline = false)
}
$message .= $line;
$line = fgets($this->socket);
};
}
}

return $message;
Expand Down Expand Up @@ -209,7 +209,6 @@ public function logout()
}
}


/**
* Get capabilities from POP3 server
*
Expand All @@ -221,7 +220,6 @@ public function capa()
return explode("\n", $result);
}


/**
* Login to POP3 server. Can use APOP
*
Expand All @@ -244,7 +242,6 @@ public function login($user, $password, $tryApop = true)
$this->request("PASS $password");
}


/**
* Make STAT call for message count and size sum
*
Expand All @@ -260,7 +257,6 @@ public function status(&$messages, &$octets)
list($messages, $octets) = explode(' ', $result);
}


/**
* Make LIST call for size of message(s)
*
Expand Down Expand Up @@ -288,7 +284,6 @@ public function getList($msgno = null)
return $messages;
}


/**
* Make UIDL call for getting a uniqueid
*
Expand Down Expand Up @@ -319,7 +314,6 @@ public function uniqueid($msgno = null)
return $messages;
}


/**
* Make TOP call for getting headers and maybe some body lines
* This method also sets hasTop - before it it's not known if top is supported
Expand All @@ -339,9 +333,9 @@ public function top($msgno, $lines = 0, $fallback = false)
if ($this->hasTop === false) {
if ($fallback) {
return $this->retrieve($msgno);
} else {
throw new Exception\RuntimeException('top not supported and no fallback wanted');
}

throw new Exception\RuntimeException('top not supported and no fallback wanted');
}
$this->hasTop = true;

Expand Down
3 changes: 1 addition & 2 deletions src/Protocol/ProtocolTrait.php
Expand Up @@ -21,7 +21,6 @@ trait ProtocolTrait
*/
protected $novalidatecert;


public function getCryptoMethod(): int
{
// Allow the best TLS version(s) we can
Expand Down Expand Up @@ -72,7 +71,7 @@ private function prepareSocketOptions(): array
'ssl' => [
'verify_peer_name' => false,
'verify_peer' => false,
]
],
]
: [];
}
Expand Down
4 changes: 0 additions & 4 deletions src/Protocol/Smtp.php
Expand Up @@ -260,7 +260,6 @@ protected function ehlo($host)
}
}


/**
* Issues MAIL command
*
Expand All @@ -282,7 +281,6 @@ public function mail($from)
$this->data = false;
}


/**
* Issues RCPT command
*
Expand All @@ -301,7 +299,6 @@ public function rcpt($to)
$this->rcpt = true;
}


/**
* Issues DATA command
*
Expand Down Expand Up @@ -343,7 +340,6 @@ public function data($data)
$this->data = true;
}


/**
* Issues the RSET command end validates answer
*
Expand Down
16 changes: 8 additions & 8 deletions src/Storage.php
Expand Up @@ -12,12 +12,12 @@ class Storage
{
// maildir and IMAP flags, using IMAP names, where possible to be able to distinguish between IMAP
// system flags and other flags
const FLAG_PASSED = 'Passed';
const FLAG_SEEN = '\Seen';
const FLAG_UNSEEN = '\Unseen';
const FLAG_ANSWERED = '\Answered';
const FLAG_FLAGGED = '\Flagged';
const FLAG_DELETED = '\Deleted';
const FLAG_DRAFT = '\Draft';
const FLAG_RECENT = '\Recent';
public const FLAG_PASSED = 'Passed';
public const FLAG_SEEN = '\Seen';
public const FLAG_UNSEEN = '\Unseen';
public const FLAG_ANSWERED = '\Answered';
public const FLAG_FLAGGED = '\Flagged';
public const FLAG_DELETED = '\Deleted';
public const FLAG_DRAFT = '\Draft';
public const FLAG_RECENT = '\Recent';
}
4 changes: 2 additions & 2 deletions src/Storage/Folder.php
Expand Up @@ -61,7 +61,7 @@ public function __construct($localName, $globalName = '', $selectable = true, ar
public function hasChildren()
{
$current = $this->current();
return $current && $current instanceof Folder && ! $current->isLeaf();
return $current && $current instanceof self && ! $current->isLeaf();
}

/**
Expand Down Expand Up @@ -142,7 +142,7 @@ public function __get($name)
* @param string $name local name of subfolder
* @param \Laminas\Mail\Storage\Folder $folder instance for new subfolder
*/
public function __set($name, Folder $folder)
public function __set($name, self $folder)
{
$this->folders[$name] = $folder;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Storage/Folder/Mbox.php
Expand Up @@ -8,6 +8,7 @@

namespace Laminas\Mail\Storage\Folder;

use Laminas\Config\Config;
use Laminas\Mail\Storage;
use Laminas\Mail\Storage\Exception;
use Laminas\Stdlib\ErrorHandler;
Expand Down Expand Up @@ -43,7 +44,7 @@ class Mbox extends Storage\Mbox implements FolderInterface
* - dirname rootdir of mbox structure
* - folder initial selected folder, default is 'INBOX'
*
* @param $params array mail reader specific parameters
* @param $params array|object|Config mail reader specific parameters
* @throws Exception\InvalidArgumentException
*/
public function __construct($params)
Expand Down

0 comments on commit c1f2125

Please sign in to comment.