fix conding standards

This commit is contained in:
azjezz 2020-03-01 21:52:25 +01:00
parent be8a83d9e6
commit 5ff154f00d
17 changed files with 116 additions and 116 deletions

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Psl\Asio;
use Psl;
use Exception;
use Psl;
/**
* Represents a result of operation that either has a successful result or the exception object if that operation failed.

View File

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Psl\Asio;
use Exception;
use Psl;
use Psl\Str;
use Exception;
/**
* Represents the result of failed operation.

View File

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Psl\Asio;
use Exception;
use Psl;
use Psl\Str;
use Exception;
/**
* Represents the result of successful operation.

View File

@ -11,7 +11,8 @@ namespace Psl\Collection;
* @extends IMap<Tk, Tv>
* @extends IMutableAccessibleCollection<Tk, Tv>
*/
interface IMutableMap extends IMap, IMutableAccessibleCollection {
interface IMutableMap extends IMap, IMutableAccessibleCollection
{
/**
* Returns a `IMutableVector` containing the values of the current
* `IMutableMap`.

View File

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Psl\Gen;
use Generator;
use Iterator;
use Psl;
use Psl\Iter;
use Iterator;
use Generator;
/**
* @template Tk
@ -91,7 +91,7 @@ final class RewindableGenerator implements Iterator
$valid = $this->iterator->valid();
if (!$valid && $this->iterator instanceof Generator) {
/** @psalm-var (Closure(): Generator<Tk, Tv, mixed, void>) $generator */
$generator = function(): Generator {
$generator = function (): Generator {
foreach ($this->cache as [$k, $v]) {
yield $k => $v;
}

View File

@ -35,7 +35,7 @@ function product(iterable ...$iterables): iterable
/** @psalm-var array<int, Iter\Iterator<Tk, Tv>> $iterators */
$iterators = Iter\to_array(Iter\map(
$iterables,
fn(iterable $iterable) => new Iter\Iterator($iterable)
fn (iterable $iterable) => new Iter\Iterator($iterable)
));
$numIterators = count($iterators);

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Psl\Gen;
use Psl\Iter;
use Generator;
use Psl\Iter;
/**
* Reverse the given iterable.

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Psl\Gen;
use Psl\Iter;
use Generator;
use Psl\Iter;
/**
* Zips the iterables that were passed as arguments.

View File

@ -13,14 +13,6 @@ namespace Psl\Internal;
*/
final class Loader
{
private const TypeConstant = 1;
private const TypeFunction = 2;
private const TypeInterface = 4;
private const TypeTrait = 8;
private const TypeClass = 16;
private const TypeClassish = self::TypeInterface | self::TypeTrait | self::TypeClass;
public const Constants = [
'Psl\Internal\ALPHABET_BASE64',
'Psl\Internal\ALPHABET_BASE64_URL',
@ -315,6 +307,13 @@ final class Loader
'Psl\Asio\WrappedException',
'Psl\Asio\WrappedResult',
];
private const TypeConstant = 1;
private const TypeFunction = 2;
private const TypeInterface = 4;
private const TypeTrait = 8;
private const TypeClass = 16;
private const TypeClassish = self::TypeInterface | self::TypeTrait | self::TypeClass;
private function __construct()
{
@ -324,7 +323,7 @@ final class Loader
{
if (!\function_exists(self::Functions[0])) {
self::preload();
} else if (!\defined(self::Constants[0])) {
} elseif (!\defined(self::Constants[0])) {
self::loadConstants();
}
}
@ -332,7 +331,7 @@ final class Loader
public static function preload(): void
{
static::loadConstants();
static::autoload(static function(): void {
static::autoload(static function (): void {
static::loadFunctions();
static::loadInterfaces();
static::loadTraits();
@ -342,7 +341,7 @@ final class Loader
private static function autoload(callable $callback): void
{
$loader = static function(string $classname): ?bool {
$loader = static function (string $classname): ?bool {
if ('P' === $classname[0] && 0 === \strpos($classname, 'Psl\\')) {
require_once static::getFile($classname, self::TypeClassish);
@ -424,7 +423,7 @@ final class Loader
$lastSeparatorPosition = \strrpos($typename, '\\');
$namespace = substr($typename, 0, $lastSeparatorPosition);
if ($type === ($type & self::TypeClassish) || ($type === ($type & self::TypeFunction))) {
if (($type & self::TypeClassish) === $type || (($type & self::TypeFunction) === $type)) {
$file = \substr($typename, $lastSeparatorPosition + 1) . '.php';
} else {
$file = 'constants.php';

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Psl\Tests\Asio;
use Psl\Asio;
use PHPUnit\Framework\TestCase;
use Psl\Asio;
use Psl\Exception\InvariantViolationException;
class WrapTest extends TestCase
@ -13,7 +13,7 @@ class WrapTest extends TestCase
public function testWrapException(): void
{
$exception = new \Exception('foo');
$wrapper = Asio\wrap(static function() use ($exception): void {
$wrapper = Asio\wrap(static function () use ($exception): void {
throw $exception;
});
$this->assertFalse($wrapper->isSucceeded());
@ -27,7 +27,7 @@ class WrapTest extends TestCase
public function testWrapResult(): void
{
$wrapper = Asio\wrap(static function(): string {
$wrapper = Asio\wrap(static function (): string {
return 'foo';
});
$this->assertTrue($wrapper->isSucceeded());

View File

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace Psl\Tests\Asio;
use Psl\Asio\WrappedException;
use PHPUnit\Framework\TestCase;
use Psl\Asio\WrappedException;
class WrappedExceptionTest extends TestCase
{

View File

@ -1,10 +1,11 @@
<?php
declare(strict_types=1);
namespace Psl\Tests\Asio;
use Psl\Asio\WrappedResult;
use PHPUnit\Framework\TestCase;
use Psl\Asio\WrappedResult;
use Psl\Exception\InvariantViolationException;
class WrappedResultTest extends TestCase

View File

@ -4,11 +4,11 @@ declare(strict_types=1);
namespace Psl\Tests\Collection;
use Psl\Str;
use PHPUnit\Framework\TestCase;
use Psl\Collection\IMap;
use Psl\Collection\IVector;
use PHPUnit\Framework\TestCase;
use Psl\Exception\InvariantViolationException;
use Psl\Str;
/**
* @covers \Psl\Collection\AbstractMap
@ -30,16 +30,6 @@ abstract class AbstractMapTest extends TestCase
*/
protected string $vectorClass = IVector::class;
/**
* @template Tk of array-key
* @template Tv
*
* @psalm-param iterable<Tk, Tv> $items
*
* @psalm-return IMap<Tk, Tv>
*/
abstract protected function create(iterable $items): IMap;
public function testIsEmpty(): void
{
$this->assertTrue($this->create([])->isEmpty());
@ -116,7 +106,7 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$filtered = $map->filter(fn(string $item) => Str\contains($item, 'b'));
$filtered = $map->filter(fn (string $item) => Str\contains($item, 'b'));
$this->assertInstanceOf($this->mapClass, $filtered);
$this->assertNotSame($map, $filtered);
@ -133,7 +123,7 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$filtered = $map->filter(fn(string $item) => Str\contains($item, 'hello'));
$filtered = $map->filter(fn (string $item) => Str\contains($item, 'hello'));
$this->assertInstanceOf($this->mapClass, $filtered);
$this->assertNotContains('bar', $filtered);
@ -152,7 +142,7 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$filtered = $map->filterWithKey(fn(int $k, string $v) => $v === 'foo' || $k === 3);
$filtered = $map->filterWithKey(fn (int $k, string $v) => 'foo' === $v || 3 === $k);
$this->assertInstanceOf($this->mapClass, $filtered);
$this->assertNotSame($map, $filtered);
@ -169,7 +159,7 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$filtered = $map->filterWithKey(fn(int $k, string $v) => $k === 4);
$filtered = $map->filterWithKey(fn (int $k, string $v) => 4 === $k);
$this->assertInstanceOf($this->mapClass, $filtered);
$this->assertNotContains('bar', $filtered);
@ -188,7 +178,7 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$mapped = $map->map(fn(string $item) => Str\uppercase($item));
$mapped = $map->map(fn (string $item) => Str\uppercase($item));
$this->assertInstanceOf($this->mapClass, $mapped);
$this->assertSame([
@ -207,7 +197,7 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$mapped = $map->map(fn(string $item) => $item);
$mapped = $map->map(fn (string $item) => $item);
$this->assertInstanceOf($this->mapClass, $mapped);
$this->assertNotSame($map, $mapped);
@ -224,7 +214,7 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$mapped = $map->mapWithKey(fn(int $k, string $v) => Str\format('%s ( %d )', $v, $k));
$mapped = $map->mapWithKey(fn (int $k, string $v) => Str\format('%s ( %d )', $v, $k));
$this->assertInstanceOf($this->mapClass, $mapped);
$this->assertSame([
@ -243,14 +233,14 @@ abstract class AbstractMapTest extends TestCase
3 => 'qux',
]);
$mapped = $map->mapWithKey(fn(int $k, string $v) => $k);
$mapped = $map->mapWithKey(fn (int $k, string $v) => $k);
$this->assertInstanceOf($this->mapClass, $mapped);
$this->assertNotSame($map, $mapped);
$this->assertSame($map->keys()->toArray(), $mapped->toArray());
$this->assertCount(4, $mapped);
$mapped = $map->mapWithKey(fn(int $k, string $v) => $v);
$mapped = $map->mapWithKey(fn (int $k, string $v) => $v);
$this->assertInstanceOf($this->mapClass, $mapped);
$this->assertNotSame($map, $mapped);
@ -398,26 +388,26 @@ abstract class AbstractMapTest extends TestCase
public function testTakeWhile(): void
{
$map = $this->create([]);
$rest = $map->takeWhile(fn($v) => false);
$rest = $map->takeWhile(fn ($v) => false);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(0, $rest);
$map = $this->create([]);
$rest = $map->takeWhile(fn($v) => true);
$rest = $map->takeWhile(fn ($v) => true);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(0, $rest);
$map = $this->create(['foo' => 'bar', 'baz' => 'qux']);
$rest = $map->takeWhile(fn($v) => true);
$rest = $map->takeWhile(fn ($v) => true);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(2, $rest);
$this->assertSame($map->toArray(), $rest->toArray());
$map = $this->create(['foo' => 'bar', 'baz' => 'qux']);
$rest = $map->takeWhile(fn($v) => $v === 'bar');
$rest = $map->takeWhile(fn ($v) => 'bar' === $v);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(1, $rest);
@ -456,32 +446,32 @@ abstract class AbstractMapTest extends TestCase
public function testDropWhile(): void
{
$map = $this->create([]);
$rest = $map->dropWhile(fn($v) => true);
$rest = $map->dropWhile(fn ($v) => true);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(0, $rest);
$map = $this->create([]);
$rest = $map->dropWhile(fn($v) => false);
$rest = $map->dropWhile(fn ($v) => false);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(0, $rest);
$map = $this->create(['foo' => 'bar', 'baz' => 'qux']);
$rest = $map->dropWhile(fn($v) => true);
$rest = $map->dropWhile(fn ($v) => true);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(0, $rest);
$map = $this->create(['foo' => 'bar', 'baz' => 'qux']);
$rest = $map->dropWhile(fn($v) => false);
$rest = $map->dropWhile(fn ($v) => false);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(2, $rest);
$this->assertSame($map->toArray(), $rest->toArray());
$map = $this->create(['foo' => 'bar', 'baz' => 'qux']);
$rest = $map->dropWhile(fn($v) => $v === 'bar');
$rest = $map->dropWhile(fn ($v) => 'bar' === $v);
$this->assertInstanceOf($this->mapClass, $rest);
$this->assertNotSame($map, $rest);
$this->assertCount(1, $rest);
@ -558,4 +548,14 @@ abstract class AbstractMapTest extends TestCase
$this->assertSame('world', $map->get('bar'));
$this->assertNull($map->get('baz'));
}
/**
* @template Tk of array-key
* @template Tv
*
* @psalm-param iterable<Tk, Tv> $items
*
* @psalm-return IMap<Tk, Tv>
*/
abstract protected function create(iterable $items): IMap;
}

View File

@ -4,10 +4,10 @@ declare(strict_types=1);
namespace Psl\Tests\Collection;
use Psl\Str;
use Psl\Collection\IVector;
use PHPUnit\Framework\TestCase;
use Psl\Collection\IVector;
use Psl\Exception\InvariantViolationException;
use Psl\Str;
/**
* @covers \Psl\Collection\AbstractVector
@ -22,15 +22,6 @@ abstract class AbstractVectorTest extends TestCase
*/
protected string $vectorClass = IVector::class;
/**
* @template T
*
* @psalm-param iterable<T> $items
*
* @psalm-return IVector<T>
*/
abstract protected function create(iterable $items): IVector;
public function testIsEmpty(): void
{
$this->assertTrue($this->create([])->isEmpty());
@ -103,7 +94,7 @@ abstract class AbstractVectorTest extends TestCase
'qux',
]);
$filtered = $vector->filter(fn(string $item) => Str\contains($item, 'b'));
$filtered = $vector->filter(fn (string $item) => Str\contains($item, 'b'));
$this->assertInstanceOf($this->vectorClass, $filtered);
$this->assertNotSame($vector, $filtered);
@ -120,7 +111,7 @@ abstract class AbstractVectorTest extends TestCase
'qux',
]);
$filtered = $vector->filter(fn(string $item) => Str\contains($item, 'hello'));
$filtered = $vector->filter(fn (string $item) => Str\contains($item, 'hello'));
$this->assertInstanceOf($this->vectorClass, $filtered);
$this->assertNotContains('bar', $filtered);
@ -139,7 +130,7 @@ abstract class AbstractVectorTest extends TestCase
'qux',
]);
$filtered = $vector->filterWithKey(fn(int $k, string $v) => $v === 'foo' || $k === 3);
$filtered = $vector->filterWithKey(fn (int $k, string $v) => 'foo' === $v || 3 === $k);
$this->assertInstanceOf($this->vectorClass, $filtered);
$this->assertNotSame($vector, $filtered);
@ -156,7 +147,7 @@ abstract class AbstractVectorTest extends TestCase
'qux',
]);
$filtered = $vector->filterWithKey(fn(int $k, string $v) => $k === 4);
$filtered = $vector->filterWithKey(fn (int $k, string $v) => 4 === $k);
$this->assertInstanceOf($this->vectorClass, $filtered);
$this->assertNotContains('bar', $filtered);
@ -175,7 +166,7 @@ abstract class AbstractVectorTest extends TestCase
'qux',
]);
$mapped = $vector->map(fn(string $item) => Str\uppercase($item));
$mapped = $vector->map(fn (string $item) => Str\uppercase($item));
$this->assertInstanceOf($this->vectorClass, $mapped);
$this->assertSame([
@ -194,7 +185,7 @@ abstract class AbstractVectorTest extends TestCase
'qux',
]);
$mapped = $vector->map(fn(string $item) => $item);
$mapped = $vector->map(fn (string $item) => $item);
$this->assertInstanceOf($this->vectorClass, $mapped);
$this->assertNotSame($vector, $mapped);
@ -211,7 +202,7 @@ abstract class AbstractVectorTest extends TestCase
3 => 'qux',
]);
$mapped = $vector->mapWithKey(fn(int $k, string $v) => Str\format('%s ( %d )', $v, $k));
$mapped = $vector->mapWithKey(fn (int $k, string $v) => Str\format('%s ( %d )', $v, $k));
$this->assertInstanceOf($this->vectorClass, $mapped);
$this->assertSame([
@ -230,14 +221,14 @@ abstract class AbstractVectorTest extends TestCase
'qux',
]);
$mapped = $vector->mapWithKey(fn(int $k, string $v) => $k);
$mapped = $vector->mapWithKey(fn (int $k, string $v) => $k);
$this->assertInstanceOf($this->vectorClass, $mapped);
$this->assertNotSame($vector, $mapped);
$this->assertSame($vector->keys()->toArray(), $mapped->toArray());
$this->assertCount(4, $mapped);
$mapped = $vector->mapWithKey(fn(int $k, string $v) => $v);
$mapped = $vector->mapWithKey(fn (int $k, string $v) => $v);
$this->assertInstanceOf($this->vectorClass, $mapped);
$this->assertNotSame($vector, $mapped);
@ -385,26 +376,26 @@ abstract class AbstractVectorTest extends TestCase
public function testTakeWhile(): void
{
$vector = $this->create([]);
$rest = $vector->takeWhile(fn($v) => false);
$rest = $vector->takeWhile(fn ($v) => false);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(0, $rest);
$vector = $this->create([]);
$rest = $vector->takeWhile(fn($v) => true);
$rest = $vector->takeWhile(fn ($v) => true);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(0, $rest);
$vector = $this->create(['bar', 'qux']);
$rest = $vector->takeWhile(fn($v) => true);
$rest = $vector->takeWhile(fn ($v) => true);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(2, $rest);
$this->assertSame($vector->toArray(), $rest->toArray());
$vector = $this->create(['bar', 'qux']);
$rest = $vector->takeWhile(fn($v) => $v === 'bar');
$rest = $vector->takeWhile(fn ($v) => 'bar' === $v);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(1, $rest);
@ -443,32 +434,32 @@ abstract class AbstractVectorTest extends TestCase
public function testDropWhile(): void
{
$vector = $this->create([]);
$rest = $vector->dropWhile(fn($v) => true);
$rest = $vector->dropWhile(fn ($v) => true);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(0, $rest);
$vector = $this->create([]);
$rest = $vector->dropWhile(fn($v) => false);
$rest = $vector->dropWhile(fn ($v) => false);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(0, $rest);
$vector = $this->create(['bar', 'qux']);
$rest = $vector->dropWhile(fn($v) => true);
$rest = $vector->dropWhile(fn ($v) => true);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(0, $rest);
$vector = $this->create(['bar', 'qux']);
$rest = $vector->dropWhile(fn($v) => false);
$rest = $vector->dropWhile(fn ($v) => false);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(2, $rest);
$this->assertSame($vector->toArray(), $rest->toArray());
$vector = $this->create(['bar', 'qux']);
$rest = $vector->dropWhile(fn($v) => $v === 'bar');
$rest = $vector->dropWhile(fn ($v) => 'bar' === $v);
$this->assertInstanceOf($this->vectorClass, $rest);
$this->assertNotSame($vector, $rest);
$this->assertCount(1, $rest);
@ -545,4 +536,13 @@ abstract class AbstractVectorTest extends TestCase
$this->assertSame('world', $vector->get(1));
$this->assertNull($vector->get(2));
}
/**
* @template T
*
* @psalm-param iterable<T> $items
*
* @psalm-return IVector<T>
*/
abstract protected function create(iterable $items): IVector;
}

View File

@ -24,19 +24,6 @@ final class MutableMapTest extends AbstractMapTest
*/
protected string $vectorClass = MutableVector::class;
/**
* @template Tk of array-key
* @template Tv
*
* @psalm-param iterable<Tk, Tv> $items
*
* @psalm-return MutableMap<Tk, Tv>
*/
protected function create(iterable $items): MutableMap
{
return new MutableMap($items);
}
public function testClear(): void
{
$map = $this->create(['foo' => 'bar']);
@ -158,4 +145,17 @@ final class MutableMapTest extends AbstractMapTest
$this->assertNull($map->get('foo'));
$this->assertNull($map->get('bar'));
}
/**
* @template Tk of array-key
* @template Tv
*
* @psalm-param iterable<Tk, Tv> $items
*
* @psalm-return MutableMap<Tk, Tv>
*/
protected function create(iterable $items): MutableMap
{
return new MutableMap($items);
}
}

View File

@ -5,8 +5,8 @@ declare(strict_types=1);
namespace Psl\Tests\Collection;
use Psl\Collection\Map;
use Psl\Collection\Vector;
use Psl\Collection\MutableVector;
use Psl\Collection\Vector;
use Psl\Exception\InvariantViolationException;
final class MutableVectorTest extends AbstractVectorTest
@ -18,18 +18,6 @@ final class MutableVectorTest extends AbstractVectorTest
*/
protected string $vectorClass = MutableVector::class;
/**
* @template T
*
* @psalm-param iterable<T> $items
*
* @psalm-return MutableVector<T>
*/
protected function create(iterable $items): MutableVector
{
return new MutableVector($items);
}
public function testClear(): void
{
$vector = $this->create(['foo', 'bar']);
@ -150,5 +138,16 @@ final class MutableVectorTest extends AbstractVectorTest
$this->assertCount(1, $vector);
$this->assertSame('baz', $vector->get(0));
}
}
/**
* @template T
*
* @psalm-param iterable<T> $items
*
* @psalm-return MutableVector<T>
*/
protected function create(iterable $items): MutableVector
{
return new MutableVector($items);
}
}

View File

@ -4,9 +4,9 @@ declare(strict_types=1);
namespace Psl\Tests\Gen;
use Psl\Gen;
use PHPUnit\Framework\TestCase;
use Psl\Collection\MutableVector;
use Psl\Gen;
class RewindableGeneratorTest extends TestCase
{
@ -14,7 +14,7 @@ class RewindableGeneratorTest extends TestCase
{
$spy = new MutableVector([]);
$generator = (static function() use ($spy): iterable {
$generator = (static function () use ($spy): iterable {
for ($i = 0; $i < 3; $i++) {
$spy->add('generator (' . $i . ')');
@ -69,7 +69,7 @@ class RewindableGeneratorTest extends TestCase
{
$spy = new MutableVector([]);
$generator = (static function() use ($spy): iterable {
$generator = (static function () use ($spy): iterable {
for ($i = 0; $i < 3; $i++) {
$spy->add($e = 'generator (' . $i . ')');
yield $i;