Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coding-standards #181

Merged
merged 5 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
.php_cs.cache
composer.lock
phpunit.xml
41 changes: 41 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP70Migration' => true,
'@PHP70Migration:risky' => true,
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_before_statement' => true,
'concat_space' => ['spacing' => 'one'],
'heredoc_to_nowdoc' => true,
'list_syntax' => ['syntax' => 'long'],
'method_argument_space' => ['ensure_fully_multiline' => true],
'no_break_comment' => true,
'no_extra_consecutive_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_superfluous_elseif' => true,
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'phpdoc_types_order' => true,
'semicolon_after_instruction' => true,
'simplified_null_return' => true,
'yoda_style' => false,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
)
;

3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ matrix:
fast_finish: true
include:
- php: 7.0
env: CS_CHECK=1
- php: 7.1
- php: 7.2
env: CODE_COVERAGE=1
Expand All @@ -28,10 +29,12 @@ cache:
install:
- sh .travis/dovecot_install.sh
- if [ "$CODE_COVERAGE" != 1 ]; then phpenv config-rm xdebug.ini || true; fi
- if [ "$CS_CHECK" != 1 ]; then composer remove --no-update --no-scripts --dev friendsofphp/php-cs-fixer; fi
- composer install

script:
- vendor/bin/phpunit --coverage-clover ./clover.xml
- if [ "$CS_CHECK" = 1 ]; then vendor/bin/php-cs-fixer fix --diff --dry-run --verbose; fi

after_script:
- if [ "$CODE_COVERAGE" = 1 ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"require-dev": {
"ext-mbstring": "*",
"ext-iconv": "*",
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^5.7",
"friendsofphp/php-cs-fixer": "^2.6"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 7 additions & 3 deletions src/Connection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap;

use Ddeboer\Imap\Exception\Exception;
Expand Down Expand Up @@ -66,8 +68,9 @@ public function hasMailbox($name)
*
* @param string $name Mailbox name
*
* @return Mailbox
* @throws MailboxDoesNotExistException If mailbox does not exist
*
* @return Mailbox
*/
public function getMailbox($name)
{
Expand All @@ -93,8 +96,9 @@ public function count()
*
* @param $name
*
* @return Mailbox
* @throws Exception
*
* @return Mailbox
*/
public function createMailbox($name)
{
Expand Down Expand Up @@ -143,7 +147,7 @@ public function getResource()

/**
* Get mailbox names
*
*
* @return array
*/
private function getMailboxNames()
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/AuthenticationFailedException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Exception;

class AuthenticationFailedException extends Exception
Expand Down
6 changes: 4 additions & 2 deletions src/Exception/Exception.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Exception;

class Exception extends \RuntimeException
{
protected $errors = array();
protected $errors = [];

public function __construct($message, $code = null, $previous = null)
public function __construct($message, $code = 0, $previous = null)
{
parent::__construct($message, $code, $previous);
$this->errors = imap_errors();
Expand Down
4 changes: 3 additions & 1 deletion src/Exception/MailboxDoesNotExistException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Exception;

class MailboxDoesNotExistException extends Exception
{
public function __construct($mailbox)
{
parent::__construct('Mailbox ' . $mailbox. ' does not exist');
parent::__construct('Mailbox ' . $mailbox . ' does not exist');
}
}
2 changes: 2 additions & 0 deletions src/Exception/MessageDeleteException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Exception;

class MessageDeleteException extends Exception
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/MessageDoesNotExistException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Exception;

class MessageDoesNotExistException extends Exception
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/MessageMoveException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Exception;

class MessageMoveException extends Exception
Expand Down
12 changes: 6 additions & 6 deletions src/Mailbox.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap;

/**
* An IMAP mailbox (commonly referred to as a ‘folder’)
*
*/
class Mailbox implements \Countable, \IteratorAggregate
{
Expand All @@ -22,7 +23,7 @@ public function __construct($name, Connection $connection)
{
$this->mailbox = $name;
$this->connection = $connection;
$this->name = substr($name, strpos($name, '}')+1);
$this->name = substr($name, strpos($name, '}') + 1);
}

/**
Expand Down Expand Up @@ -52,7 +53,7 @@ public function count()
*
* @param SearchExpression $search Search expression (optional)
*
* @return MessageIterator|Message[]
* @return Message[]|MessageIterator
*/
public function getMessages(SearchExpression $search = null)
{
Expand All @@ -63,7 +64,7 @@ public function getMessages(SearchExpression $search = null)
$messageNumbers = imap_search($this->connection->getResource(), $query, \SE_UID);
if (false == $messageNumbers) {
// imap_search can also return false
$messageNumbers = array();
$messageNumbers = [];
}

return new MessageIterator($this->connection->getResource(), $messageNumbers);
Expand Down Expand Up @@ -97,7 +98,6 @@ public function getIterator()

/**
* Delete this mailbox
*
*/
public function delete()
{
Expand All @@ -123,7 +123,7 @@ public function expunge()
*
* @param string $message
*
* @return boolean
* @return bool
*/
public function addMessage($message)
{
Expand Down
30 changes: 18 additions & 12 deletions src/Message.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap;

use Ddeboer\Imap\Exception\MessageDoesNotExistException;
use Ddeboer\Imap\Message\EmailAddress;
use Ddeboer\Imap\Exception\MessageDeleteException;
use Ddeboer\Imap\Exception\MessageDoesNotExistException;
use Ddeboer\Imap\Exception\MessageMoveException;
use Ddeboer\Imap\Message\EmailAddress;

/**
* An IMAP message (e-mail)
Expand All @@ -16,7 +18,7 @@ class Message extends Message\Part
private $attachments;

/**
* @var boolean
* @var bool
*/
private $keepUnseen = false;

Expand Down Expand Up @@ -109,6 +111,8 @@ public function getSize()
/**
* Get raw part content
*
* @param mixed $keepUnseen
*
* @return string
*/
public function getContent($keepUnseen = false)
Expand All @@ -123,7 +127,7 @@ public function getContent($keepUnseen = false)
/**
* Get message answered flag value (from headers)
*
* @return boolean
* @return bool
*/
public function isAnswered()
{
Expand All @@ -133,7 +137,7 @@ public function isAnswered()
/**
* Get message deleted flag value (from headers)
*
* @return boolean
* @return bool
*/
public function isDeleted()
{
Expand All @@ -143,7 +147,7 @@ public function isDeleted()
/**
* Get message draft flag value (from headers)
*
* @return boolean
* @return bool
*/
public function isDraft()
{
Expand All @@ -153,14 +157,14 @@ public function isDraft()
/**
* Has the message been marked as read?
*
* @return boolean
* @return bool
*/
public function isSeen()
{
return (
return
'R' === $this->getHeaders()->get('recent')
|| ('' === $this->getHeaders()->get('recent') && '' !== $this->getHeaders()->get('unseen'))
);
|| ('' === $this->getHeaders()->get('recent') && '' !== $this->getHeaders()->get('unseen'))
;
}

/**
Expand All @@ -184,7 +188,7 @@ public function getHeaders()
// imap_header is much faster than imap_fetchheader
// imap_header returns only a subset of all mail headers,
// but it does include the message flags.
$headers = imap_header($this->stream, imap_msgno($this->stream, $this->messageNumber));
$headers = imap_headerinfo($this->stream, imap_msgno($this->stream, $this->messageNumber));
$this->headers = new Message\Headers($headers);
}

Expand Down Expand Up @@ -232,7 +236,7 @@ public function getBodyText()
public function getAttachments()
{
if (null === $this->attachments) {
$this->attachments = array();
$this->attachments = [];
foreach ($this->getParts() as $part) {
if ($part instanceof Message\Attachment) {
$this->attachments[] = $part;
Expand Down Expand Up @@ -277,9 +281,11 @@ public function delete()

/**
* Move message to another mailbox
*
* @param Mailbox $mailbox
*
* @throws MessageMoveException
*
* @return Message
*/
public function move(Mailbox $mailbox)
Expand Down
2 changes: 2 additions & 0 deletions src/Message/Attachment.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Message;

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Message/EmailAddress.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Ddeboer\Imap\Message;

/**
Expand All @@ -17,7 +19,7 @@ public function __construct($mailbox, $hostname = null, $name = null)
$this->mailbox = $mailbox;
$this->hostname = $hostname;
$this->name = $name;

if ($hostname) {
$this->address = $mailbox . '@' . $hostname;
}
Expand All @@ -36,9 +38,9 @@ public function getAddress()
public function getFullAddress()
{
if ($this->name) {
$address = sprintf("%s <%s@%s>", $this->name, $this->mailbox, $this->hostname);
$address = sprintf('%s <%s@%s>', $this->name, $this->mailbox, $this->hostname);
} else {
$address = sprintf("%s@%s", $this->mailbox, $this->hostname);
$address = sprintf('%s@%s', $this->mailbox, $this->hostname);
}

return $address;
Expand Down
Loading