[FEATURE] add phpcs using PSR2

This commit is contained in:
Marco Stoll 2019-06-26 11:36:01 +02:00
parent ea8520c0ee
commit 17b8109c2f
10 changed files with 25 additions and 20 deletions

3
bin/phpcs.bat Normal file
View File

@ -0,0 +1,3 @@
@ECHO OFF
SET PROJECT_HOME=C:\dev\ffe\fastforward\DataStructures
vendor\bin\phpcs --report=xml --report-file="%PROJECT_HOME%\logs\phpcs\report.xml" --standard=PSR2 %PROJECT_HOME%\src %PROJECT_HOME%\tests -p

View File

@ -18,6 +18,7 @@
},
"require-dev": {
"phpunit/phpunit": "^8",
"squizlabs/php_codesniffer": "^3",
"theseer/phpdox": "*"
},
"repositories": [

View File

@ -85,11 +85,9 @@
</source>
<!-- PHP Code Sniffer findings -->
<!--
<source type="phpcs">
<file name="logs/phpcs.xml" />
<file name="../logs/phpcs/report.xml" />
</source>
-->
<!-- PHPMessDetector -->
<!--

View File

@ -142,4 +142,4 @@ class Collection implements \Countable, \IteratorAggregate
}
// </editor-fold>
}
}

View File

@ -58,7 +58,9 @@ class IndexedCollection extends Collection implements \ArrayAccess
public function set($index, $item)
{
// check for null items
if (is_null($item)) return $this->unset($index);
if (is_null($item)) {
return $this->unset($index);
}
$this->items[$index] = $item;
return $this;
@ -137,4 +139,4 @@ class IndexedCollection extends Collection implements \ArrayAccess
}
// </editor-fold>
}
}

View File

@ -84,7 +84,9 @@ class OrderedCollection extends IndexedCollection
}
// check for null items
if (is_null($item)) return $this->unset($offset);
if (is_null($item)) {
return $this->unset($offset);
}
if ($this->has($offset)) {
// replace
@ -240,4 +242,4 @@ class OrderedCollection extends IndexedCollection
}
// </editor-fold>
}
}

View File

@ -281,4 +281,4 @@ class Record implements \IteratorAggregate
}
// </editor-fold>
}
}

View File

@ -104,7 +104,7 @@ class CollectionTest extends TestCase
*/
public function testMap()
{
$callback = function($item) {
$callback = function ($item) {
return (string)$item . '::' . gettype($item);
};
@ -124,11 +124,11 @@ class CollectionTest extends TestCase
*/
public function testFilter()
{
$filterString = function($item) {
$filterString = function ($item) {
return is_string($item);
};
$filterAll = function($item) {
$filterAll = function ($item) {
return false;
};

View File

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace FF\Tests\DataStructures;
use FF\DataStructures\Collection;
use FF\DataStructures\OrderedCollection;
use PHPUnit\Framework\TestCase;
@ -185,7 +186,6 @@ class OrderedCollectionTest extends TestCase
{
$this->uut->push(...self::SOME_ITEMS);
$this->assertEquals(self::SOME_ITEMS, $this->uut->getItems());
}
/**
@ -205,7 +205,6 @@ class OrderedCollectionTest extends TestCase
{
$this->uut->unshift(...self::SOME_ITEMS);
$this->assertEquals(self::SOME_ITEMS, $this->uut->getItems());
}
/**
@ -253,7 +252,7 @@ class OrderedCollectionTest extends TestCase
*/
public function testAppendCollection()
{
$collection = new \FF\DataStructures\Collection(['foo' => 'bar', 'fii' => 'baz']);
$collection = new Collection(['foo' => 'bar', 'fii' => 'baz']);
$same = $this->uut->setItems(self::SOME_ITEMS)->append($collection);
$this->assertSame($this->uut, $same);
$this->assertSame(count(self::SOME_ITEMS) + count($collection), count($this->uut));
@ -276,7 +275,7 @@ class OrderedCollectionTest extends TestCase
*/
public function testSort()
{
$naturalSort = function($itemA, $itemB) {
$naturalSort = function ($itemA, $itemB) {
return $itemA <=> $itemB;
};

View File

@ -291,9 +291,9 @@ class RecordTest extends TestCase
{
$this->uut->setData(self::SOME_DATA);
foreach ($this->uut as $field => $value) {
$this->assertArrayHasKey($field, self::SOME_DATA);
$this->assertEquals(self::SOME_DATA[$field], $value);
}
foreach ($this->uut as $field => $value) {
$this->assertArrayHasKey($field, self::SOME_DATA);
$this->assertEquals(self::SOME_DATA[$field], $value);
}
}
}