From a2ea704a4331ef6fbbea185fe539920946c38746 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 19 Jan 2020 15:23:58 +0000 Subject: [PATCH] Use list type over int array --- composer.json | 2 +- src/Components/Blocks/Table.php | 31 +++++++++++++++------------- src/Configurables/BlockTypes.php | 34 +++++++++++++++---------------- src/Configurables/InlineTypes.php | 20 +++++++++--------- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/composer.json b/composer.json index 12eb8b1..290f083 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { "phpunit/phpunit": "^7.4||^6.5.13||^5.7.27||^4.8.36", - "vimeo/psalm": "^3.4.10", + "vimeo/psalm": "^3.8.3", "friendsofphp/php-cs-fixer": "^2.13", "infection/infection": "^0.12.0" }, diff --git a/src/Components/Blocks/Table.php b/src/Components/Blocks/Table.php index d127a90..1632348 100644 --- a/src/Components/Blocks/Table.php +++ b/src/Components/Blocks/Table.php @@ -18,19 +18,19 @@ use Erusev\Parsedown\State; */ final class Table implements AcquisitioningBlock, ContinuableBlock { - /** @var array */ + /** @var list<_Alignment|null> */ private $alignments; - /** @var array */ + /** @var list */ private $headerCells; - /** @var array> */ + /** @var list> */ private $rows; /** - * @param array $alignments - * @param array $headerCells - * @param array> $rows + * @param list<_Alignment|null> $alignments + * @param list $headerCells + * @param list> $rows */ private function __construct($alignments, $headerCells, $rows) { @@ -117,7 +117,10 @@ final class Table implements AcquisitioningBlock, ContinuableBlock return null; } - $cells = \array_map('trim', \array_slice($matches[0], 0, \count($this->alignments))); + $cells = \array_values(\array_map( + 'trim', + \array_slice($matches[0], 0, \count($this->alignments)) + )); return new self( $this->alignments, @@ -128,7 +131,7 @@ final class Table implements AcquisitioningBlock, ContinuableBlock /** * @param string $dividerRow - * @return array|null + * @return list<_Alignment|null>|null */ private static function parseAlignments($dividerRow) { @@ -137,7 +140,7 @@ final class Table implements AcquisitioningBlock, ContinuableBlock $dividerCells = \explode('|', $dividerRow); - /** @var array */ + /** @var list<_Alignment|null> */ $alignments = []; foreach ($dividerCells as $dividerCell) { @@ -170,7 +173,7 @@ final class Table implements AcquisitioningBlock, ContinuableBlock return true; } - /** @return array */ + /** @return list */ public function headerRow(State $State) { return \array_map( @@ -185,13 +188,13 @@ final class Table implements AcquisitioningBlock, ContinuableBlock ); } - /** @return array[] */ + /** @return list[] */ public function rows(State $State) { return \array_map( /** - * @param array $cells - * @return array + * @param list $cells + * @return list */ function ($cells) use ($State) { return \array_map( @@ -209,7 +212,7 @@ final class Table implements AcquisitioningBlock, ContinuableBlock ); } - /** @return array */ + /** @return list<_Alignment|null> */ public function alignments() { return $this->alignments; diff --git a/src/Configurables/BlockTypes.php b/src/Configurables/BlockTypes.php index 694fc46..398aa84 100644 --- a/src/Configurables/BlockTypes.php +++ b/src/Configurables/BlockTypes.php @@ -47,15 +47,15 @@ final class BlockTypes implements Configurable IndentedCode::class, ]; - /** @var array>> */ + /** @var array>> */ private $blockTypes; - /** @var array> */ + /** @var list> */ private $unmarkedBlockTypes; /** - * @param array>> $blockTypes - * @param array> $unmarkedBlockTypes + * @param array>> $blockTypes + * @param list> $unmarkedBlockTypes */ public function __construct(array $blockTypes, array $unmarkedBlockTypes) { @@ -74,7 +74,7 @@ final class BlockTypes implements Configurable /** * @param string $marker - * @param array> $newBlockTypes + * @param list> $newBlockTypes * @return self */ public function settingMarked($marker, array $newBlockTypes) @@ -87,7 +87,7 @@ final class BlockTypes implements Configurable /** * @param string $marker - * @param array> $newBlockTypes + * @param list> $newBlockTypes * @return self */ public function addingMarkedHighPrecedence($marker, array $newBlockTypes) @@ -103,7 +103,7 @@ final class BlockTypes implements Configurable /** * @param string $marker - * @param array> $newBlockTypes + * @param list> $newBlockTypes * @return self */ public function addingMarkedLowPrecedence($marker, array $newBlockTypes) @@ -118,7 +118,7 @@ final class BlockTypes implements Configurable } /** - * @param array> $newUnmarkedBlockTypes + * @param list> $newUnmarkedBlockTypes * @return self */ public function settingUnmarked(array $newUnmarkedBlockTypes) @@ -127,7 +127,7 @@ final class BlockTypes implements Configurable } /** - * @param array> $newBlockTypes + * @param list> $newBlockTypes * @return self */ public function addingUnmarkedHighPrecedence(array $newBlockTypes) @@ -138,7 +138,7 @@ final class BlockTypes implements Configurable } /** - * @param array> $newBlockTypes + * @param list> $newBlockTypes * @return self */ public function addingUnmarkedLowPrecedence(array $newBlockTypes) @@ -149,7 +149,7 @@ final class BlockTypes implements Configurable } /** - * @param array> $removeBlockTypes + * @param list> $removeBlockTypes * @return self */ public function removing(array $removeBlockTypes) @@ -157,21 +157,21 @@ final class BlockTypes implements Configurable return new self( \array_map( /** - * @param array> $blockTypes - * @return array> + * @param list> $blockTypes + * @return list> */ function ($blockTypes) use ($removeBlockTypes) { - return \array_diff($blockTypes, $removeBlockTypes); + return \array_values(\array_diff($blockTypes, $removeBlockTypes)); }, $this->blockTypes ), - \array_diff($this->unmarkedBlockTypes, $removeBlockTypes) + \array_values(\array_diff($this->unmarkedBlockTypes, $removeBlockTypes)) ); } /** * @param string $marker - * @return array> + * @return list> */ public function markedBy($marker) { @@ -183,7 +183,7 @@ final class BlockTypes implements Configurable } /** - * @return array> + * @return list> */ public function unmarked() { diff --git a/src/Configurables/InlineTypes.php b/src/Configurables/InlineTypes.php index 8a61169..483fd0c 100644 --- a/src/Configurables/InlineTypes.php +++ b/src/Configurables/InlineTypes.php @@ -34,14 +34,14 @@ final class InlineTypes implements Configurable "\n" => [HardBreak::class, SoftBreak::class], ]; - /** @var array>> */ + /** @var array>> */ private $inlineTypes; /** @var string */ private $inlineMarkers; /** - * @param array>> $inlineTypes + * @param array>> $inlineTypes */ public function __construct(array $inlineTypes) { @@ -57,7 +57,7 @@ final class InlineTypes implements Configurable /** * @param string $marker - * @param array> $newInlineTypes + * @param list> $newInlineTypes * @return self */ public function setting($marker, array $newInlineTypes) @@ -70,7 +70,7 @@ final class InlineTypes implements Configurable /** * @param string $marker - * @param array> $newInlineTypes + * @param list> $newInlineTypes * @return self */ public function addingHighPrecedence($marker, array $newInlineTypes) @@ -86,7 +86,7 @@ final class InlineTypes implements Configurable /** * @param string $marker - * @param array> $newInlineTypes + * @param list> $newInlineTypes * @return self */ public function addingLowPrecedence($marker, array $newInlineTypes) @@ -101,18 +101,18 @@ final class InlineTypes implements Configurable } /** - * @param array> $removeInlineTypes + * @param list> $removeInlineTypes * @return self */ public function removing(array $removeInlineTypes) { return new self(\array_map( /** - * @param array> $inlineTypes - * @return array> + * @param list> $inlineTypes + * @return list> */ function ($inlineTypes) use ($removeInlineTypes) { - return \array_diff($inlineTypes, $removeInlineTypes); + return \array_values(\array_diff($inlineTypes, $removeInlineTypes)); }, $this->inlineTypes )); @@ -120,7 +120,7 @@ final class InlineTypes implements Configurable /** * @param string $marker - * @return array> + * @return list> */ public function markedBy($marker) {