diff --git a/.gitignore b/.gitignore index d92a4ec..fb6c963 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.php_cs.cache build composer.lock phpunit.xml diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..abf03b1 --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,39 @@ +setRiskyAllowed(true) + ->setRules([ + "@PSR1" => true, + "@PSR2" => true, + "braces" => [ + "allow_single_line_closure" => true, + "position_after_functions_and_oop_constructs" => "same", + ], + "array_syntax" => ["syntax" => "short"], + "cast_spaces" => true, + "combine_consecutive_unsets" => true, + "function_to_constant" => true, + "no_multiline_whitespace_before_semicolons" => true, + "no_unused_imports" => true, + "no_useless_else" => true, + "no_useless_return" => true, + "no_whitespace_before_comma_in_array" => true, + "no_whitespace_in_blank_line" => true, + "non_printable_character" => true, + "normalize_index_brace" => true, + "ordered_imports" => true, + "php_unit_construct" => true, + "php_unit_dedicate_assert" => true, + "php_unit_fqcn_annotation" => true, + "phpdoc_summary" => true, + "phpdoc_types" => true, + "psr4" => true, + "return_type_declaration" => ["space_before" => "none"], + "short_scalar_cast" => true, + "single_blank_line_before_namespace" => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__ . "/lib") + ->in(__DIR__ . "/test") + ); \ No newline at end of file diff --git a/composer.json b/composer.json index 5a3f2c9..e80adcd 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require-dev": { "amphp/phpunit-util": "dev-master", "phpunit/phpunit": "^6", - "friendsofphp/php-cs-fixer": "~1.9" + "friendsofphp/php-cs-fixer": "^2.3" }, "autoload": { "psr-4": { diff --git a/lib/BufferIterator.php b/lib/BufferIterator.php index 5d5af26..625c279 100644 --- a/lib/BufferIterator.php +++ b/lib/BufferIterator.php @@ -7,24 +7,24 @@ namespace Amp\ByteStream; class BufferIterator implements \SeekableIterator { /** @var \Amp\ByteStream\Buffer */ private $buffer; - + /** @var int */ private $current = 0; - + /** * @param \Amp\ByteStream\Buffer $buffer */ public function __construct(Buffer $buffer) { $this->buffer = $buffer; } - + /** * Rewinds the iterator to the beginning of the buffer. */ public function rewind() { $this->current = 0; } - + /** * Determines if the iterator is valid. * @@ -33,7 +33,7 @@ class BufferIterator implements \SeekableIterator { public function valid(): bool { return isset($this->buffer[$this->current]); } - + /** * Returns the current position (key) of the iterator. * @@ -42,7 +42,7 @@ class BufferIterator implements \SeekableIterator { public function key(): int { return $this->current; } - + /** * Returns the current character in the buffer at the iterator position. * @@ -51,22 +51,21 @@ class BufferIterator implements \SeekableIterator { public function current(): string { return $this->buffer[$this->current]; } - + /** * Moves to the next character in the buffer. */ - public function next() - { + public function next() { ++$this->current; } - + /** * Moves to the previous character in the buffer. */ public function prev() { --$this->current; } - + /** * Moves to the given position in the buffer. * @@ -77,10 +76,10 @@ class BufferIterator implements \SeekableIterator { if (0 > $position) { $position = 0; } - + $this->current = $position; } - + /** * Inserts the given string into the buffer at the current iterator position. * @@ -92,10 +91,10 @@ class BufferIterator implements \SeekableIterator { if (!$this->valid()) { throw new \OutOfBoundsException('The iterator is not valid!'); } - + $this->buffer[$this->current] = $data . $this->buffer[$this->current]; } - + /** * Replaces the byte at the current iterator position with the given string. * @@ -109,14 +108,14 @@ class BufferIterator implements \SeekableIterator { if (!$this->valid()) { throw new \OutOfBoundsException('The iterator is not valid!'); } - + $temp = $this->buffer[$this->current]; - + $this->buffer[$this->current] = $data; - + return $temp; } - + /** * Removes the byte at the current iterator position and moves the iterator to the previous character. * @@ -128,13 +127,13 @@ class BufferIterator implements \SeekableIterator { if (!$this->valid()) { throw new \OutOfBoundsException('The iterator is not valid!'); } - + $temp = $this->buffer[$this->current]; - + unset($this->buffer[$this->current]); - + --$this->current; - + return $temp; } -} \ No newline at end of file +} diff --git a/lib/ClosedException.php b/lib/ClosedException.php index b9f1f62..dc7e112 100644 --- a/lib/ClosedException.php +++ b/lib/ClosedException.php @@ -2,4 +2,5 @@ namespace Amp\ByteStream; -class ClosedException extends StreamException {} +class ClosedException extends StreamException { +} diff --git a/lib/DuplexStream.php b/lib/DuplexStream.php index cd3e08d..c1aabe8 100644 --- a/lib/DuplexStream.php +++ b/lib/DuplexStream.php @@ -2,4 +2,5 @@ namespace Amp\ByteStream; -interface DuplexStream extends ReadableStream, WritableStream {} +interface DuplexStream extends ReadableStream, WritableStream { +} diff --git a/lib/Internal/functions.php b/lib/Internal/functions.php index 25a83ac..683249a 100644 --- a/lib/Internal/functions.php +++ b/lib/Internal/functions.php @@ -2,7 +2,8 @@ namespace Amp\ByteStream\Internal; -use Amp\ByteStream\{ ReadableStream, WritableStream }; +use Amp\ByteStream\ReadableStream; +use Amp\ByteStream\WritableStream; /** * @internal diff --git a/lib/Message.php b/lib/Message.php index 56ba68f..dbc2126 100644 --- a/lib/Message.php +++ b/lib/Message.php @@ -2,7 +2,11 @@ namespace Amp\ByteStream; -use Amp\{ Deferred, Promise, Stream, StreamIterator, Success }; +use Amp\Deferred; +use Amp\Promise; +use Amp\Stream; +use Amp\StreamIterator; +use Amp\Success; /** * Creates a buffered message from a Stream. The message can be consumed in chunks using the advance() and getChunk() diff --git a/lib/Parser.php b/lib/Parser.php index 5b3ccea..367a298 100644 --- a/lib/Parser.php +++ b/lib/Parser.php @@ -2,7 +2,11 @@ namespace Amp\ByteStream; -use Amp\{ Failure, InvalidYieldError, Loop, Promise, Success }; +use Amp\Failure; +use Amp\InvalidYieldError; +use Amp\Loop; +use Amp\Promise; +use Amp\Success; class Parser implements WritableStream { const CHUNK_SIZE = 8192; diff --git a/lib/StreamException.php b/lib/StreamException.php index c97e1b3..ffe8fd7 100644 --- a/lib/StreamException.php +++ b/lib/StreamException.php @@ -2,4 +2,5 @@ namespace Amp\ByteStream; -class StreamException extends \Exception {} +class StreamException extends \Exception { +} diff --git a/lib/WritableStream.php b/lib/WritableStream.php index 969c370..99f39cc 100644 --- a/lib/WritableStream.php +++ b/lib/WritableStream.php @@ -11,7 +11,7 @@ interface WritableStream { * @return \Amp\Promise Succeeds once the data has been successfully written to the stream. */ public function write(string $data): Promise; - + /** * @param string $data * diff --git a/lib/functions.php b/lib/functions.php index 2794608..aa2969c 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -2,7 +2,8 @@ namespace Amp\ByteStream; -use Amp\{ Coroutine, Promise }; +use Amp\Coroutine; +use Amp\Promise; // @codeCoverageIgnoreStart if (\strlen('…') !== 3) { diff --git a/test/MessageTest.php b/test/MessageTest.php index 3961064..a20f045 100644 --- a/test/MessageTest.php +++ b/test/MessageTest.php @@ -2,9 +2,11 @@ namespace Amp\ByteStream\Test; -use Amp\{ Emitter, Loop, Success }; use Amp\ByteStream\Message; +use Amp\Emitter; +use Amp\Loop; use Amp\PHPUnit\TestCase; +use Amp\Success; class MessageTest extends TestCase { public function testBufferingAll() {