mirror of
https://github.com/danog/byte-stream.git
synced 2024-11-26 20:04:51 +01:00
Update and fix php-cs-fixer and code style
This commit is contained in:
parent
9f22953566
commit
16fc80ae3b
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
.php_cs.cache
|
||||
build
|
||||
composer.lock
|
||||
phpunit.xml
|
||||
|
39
.php_cs.dist
Normal file
39
.php_cs.dist
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->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")
|
||||
);
|
@ -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": {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,4 +2,5 @@
|
||||
|
||||
namespace Amp\ByteStream;
|
||||
|
||||
class ClosedException extends StreamException {}
|
||||
class ClosedException extends StreamException {
|
||||
}
|
||||
|
@ -2,4 +2,5 @@
|
||||
|
||||
namespace Amp\ByteStream;
|
||||
|
||||
interface DuplexStream extends ReadableStream, WritableStream {}
|
||||
interface DuplexStream extends ReadableStream, WritableStream {
|
||||
}
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
namespace Amp\ByteStream\Internal;
|
||||
|
||||
use Amp\ByteStream\{ ReadableStream, WritableStream };
|
||||
use Amp\ByteStream\ReadableStream;
|
||||
use Amp\ByteStream\WritableStream;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -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()
|
||||
|
@ -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;
|
||||
|
@ -2,4 +2,5 @@
|
||||
|
||||
namespace Amp\ByteStream;
|
||||
|
||||
class StreamException extends \Exception {}
|
||||
class StreamException extends \Exception {
|
||||
}
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
namespace Amp\ByteStream;
|
||||
|
||||
use Amp\{ Coroutine, Promise };
|
||||
use Amp\Coroutine;
|
||||
use Amp\Promise;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (\strlen('…') !== 3) {
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user