Skip to content

Commit

Permalink
Switched to PhpCsFixer
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayne committed Aug 24, 2019
1 parent 88a9c7d commit ee32f61
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 32 deletions.
17 changes: 9 additions & 8 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . DIRECTORY_SEPARATOR . 'benchmarks',
__DIR__ . DIRECTORY_SEPARATOR . 'src',
__DIR__ . DIRECTORY_SEPARATOR . 'tests',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return Symfony\CS\Config\Config::create()
->level(\Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(['short_array_syntax'])
->finder($finder);
return PhpCsFixer\Config::create()
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder);
6 changes: 4 additions & 2 deletions src/Factory/WzClassificationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public static function buildFromFile($xmlFile)

if (!$xml) {
throw new InvalidArgumentException(
sprintf("Invalid XML file `%s`.", $xmlFile));
sprintf("Invalid XML file `%s`.", $xmlFile)
);
}

return self::buildFromXml($xml);
Expand Down Expand Up @@ -87,7 +88,8 @@ private static function buildItems(SimpleXMLElement $xml)
$itemId,
self::buildLabels($xmlItem),
$itemLevel,
$parent);
$parent
);

$items[] = $current;
$levels[$itemLevel] = $current;
Expand Down
7 changes: 5 additions & 2 deletions src/WzClassification.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __construct(array $items)
if (!$item instanceof WzItemInterface) {
throw new InvalidArgumentException(sprintf(
'Only `%s` objects are allowed.',
WzItemInterface::class));
WzItemInterface::class
));
}

$this->items[$item->getId()] = $item;
Expand Down Expand Up @@ -62,7 +63,9 @@ public function getItemsByLevel($level)
$this->items,
function (WzItemInterface $item) use ($level) {
return $item->getLevel() == $level;
}));
}
)
);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/WzItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public function getLabel($langCode)
throw new InvalidArgumentException(sprintf(
'Unsupported language code `%s`. Supported codes: `%s`.',
$langCode,
implode(',', array_keys($this->labels))));
implode(',', array_keys($this->labels))
));
}

/**
Expand Down Expand Up @@ -140,7 +141,8 @@ public function addChild(WzItemInterface $child)
"The parent of `%s` is invalid. Expected `%s` but got `%s`.",
$child->getId(),
$this->getId(),
$child->getParent() ? $child->getParent()->getId() : ''));
$child->getParent() ? $child->getParent()->getId() : ''
));
}

$this->children[] = $child;
Expand Down
18 changes: 12 additions & 6 deletions tests/Factory/WzClassificationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function testDefaultClassification()
{
$this->assertInstanceOf(
WzClassificationInterface::class,
WzClassificationFactory::build());
WzClassificationFactory::build()
);
}

public function testDefaultClassification_Count()
Expand Down Expand Up @@ -92,7 +93,8 @@ public function testDefaultClassification_Children()

$this->assertSame(
$item->getChildren(),
$item->getChildrenByLevel($item::LEVEL_SUBCLASS));
$item->getChildrenByLevel($item::LEVEL_SUBCLASS)
);

$this->assertSame('74.10.1', $item->getChildren()[0]->getId());
$this->assertSame('74.10.2', $item->getChildren()[1]->getId());
Expand Down Expand Up @@ -125,30 +127,34 @@ public function testDefaultClassification_Parents()
$this->assertSame(4, $parent->getLevel());
$this->assertSame(
'Ateliers für Textil-, Schmuck-, Grafik- u. ä. Design',
$parent->getLabel('de'));
$parent->getLabel('de')
);

$parent = $item->getParentByLevel(WzItemInterface::LEVEL_GROUP);

$this->assertSame('74.1', $parent->getId());
$this->assertSame(3, $parent->getLevel());
$this->assertSame(
'Ateliers für Textil-, Schmuck-, Grafik- u. ä. Design',
$parent->getLabel('de'));
$parent->getLabel('de')
);

$parent = $item->getParentByLevel(WzItemInterface::LEVEL_DIVISION);

$this->assertSame('74', $parent->getId());
$this->assertSame(2, $parent->getLevel());
$this->assertSame(
'Sonstige freiberufliche, wissenschaftliche und technische Tätigkeiten',
$parent->getLabel('de'));
$parent->getLabel('de')
);

$parent = $item->getParentByLevel(WzItemInterface::LEVEL_SECTION);

$this->assertSame('M', $parent->getId());
$this->assertSame(1, $parent->getLevel());
$this->assertSame(
'Erbringung von freiberuflichen, wissenschaftlichen und technischen Dienstleistungen',
$parent->getLabel('de'));
$parent->getLabel('de')
);
}
}
3 changes: 2 additions & 1 deletion tests/WzClassificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function testInvalidInput()
} catch (InvalidArgumentException $e) {
$this->assertSame(
sprintf('Only `%s` objects are allowed.', WzItemInterface::class),
$e->getMessage());
$e->getMessage()
);
}
}
}
33 changes: 22 additions & 11 deletions tests/WzItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,32 @@ public function testParentFunctions(array $map)
$this->assertSame(
$map['01.11'],
$map['01.11.0']
->getParent());
->getParent()
);

$this->assertSame(
$map['01.1'],
$map['01.11.0']
->getParent()
->getParent());
->getParent()
);

$this->assertSame(
$map['01'],
$map['01.11.0']
->getParent()
->getParent()
->getParent());
->getParent()
);

$this->assertSame(
$map['A'],
$map['01.11.0']
->getParent()
->getParent()
->getParent()
->getParent());
->getParent()
);
}

/**
Expand All @@ -153,27 +157,31 @@ public function testChildrenFunctions(array $map)
[
$map['01'],
],
$map['A']->getChildrenByLevel(2));
$map['A']->getChildrenByLevel(2)
);

$this->assertSame(
[
$map['01.1'],
],
$map['A']->getChildrenByLevel(3));
$map['A']->getChildrenByLevel(3)
);

$this->assertSame(
[
$map['01.11'],
$map['01.12'],
],
$map['A']->getChildrenByLevel(4));
$map['A']->getChildrenByLevel(4)
);

$this->assertSame(
[
$map['01.11.0'],
$map['01.12.0'],
],
$map['A']->getChildrenByLevel(5));
$map['A']->getChildrenByLevel(5)
);
}

public function testChildrenOutOfBounds()
Expand Down Expand Up @@ -263,7 +271,8 @@ public function testLabel()
} catch (InvalidArgumentException $e) {
$this->assertSame(
'Unsupported language code `fr`. Supported codes: `de,en`.',
$e->getMessage());
$e->getMessage()
);
}
}

Expand Down Expand Up @@ -300,7 +309,8 @@ public function testAddChild()
} catch (InvalidParentException $e) {
$this->assertSame(
'The parent of `P` is invalid. Expected `P` but got ``.',
$e->getMessage());
$e->getMessage()
);
}

try {
Expand All @@ -309,7 +319,8 @@ public function testAddChild()
} catch (InvalidParentException $e) {
$this->assertSame(
'The parent of `B` is invalid. Expected `A` but got `P`.',
$e->getMessage());
$e->getMessage()
);
}
}
}

0 comments on commit ee32f61

Please sign in to comment.