Skip to content

Commit

Permalink
Apply php-cs-fixer/rector rules
Browse files Browse the repository at this point in the history
  • Loading branch information
magicsunday committed Mar 18, 2024
1 parent 26e4bca commit c4c11a0
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 85 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ npm run prepare
### Run tests
```
composer update
vendor/bin/phpstan analyse -c phpstan.neon
vendor/bin/phpcs src/ --standard=PSR12
composer ci:test
composer ci:test:php:phpstan
composer ci:test:php:lint
composer ci:test:php:unit
composer ci:test:php:rector
```
2 changes: 1 addition & 1 deletion module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file is part of the package magicsunday/webtrees-descendants-chart.
*
* For the full copyright and license information, please read the
* LICENSE file distributed with this source code.
* LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
colors="true"
columns="max"
stderr="true"
bootstrap="vendor/autoload.php"
bootstrap="./.build/vendor/autoload.php"
>
<coverage processUncoveredFiles="true">
<include>
Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* This file is part of the package magicsunday/jsonmapper.
* This file is part of the package magicsunday/webtrees-descendants-chart.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
Expand Down
9 changes: 6 additions & 3 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file is part of the package magicsunday/webtrees-descendants-chart.
*
* For the full copyright and license information, please read the
* LICENSE file distributed with this source code.
* LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);
Expand All @@ -30,11 +30,14 @@ class Configuration
/**
* Tree layout variants.
*
* @see \Fisharebest\Webtrees\Module\PedigreeChartModule
* @see PedigreeChartModule
*/
public const LAYOUT_TOPBOTTOM = PedigreeChartModule::STYLE_DOWN;

public const LAYOUT_BOTTOMTOP = PedigreeChartModule::STYLE_UP;

public const LAYOUT_LEFTRIGHT = PedigreeChartModule::STYLE_RIGHT;

public const LAYOUT_RIGHTLEFT = PedigreeChartModule::STYLE_LEFT;

/**
Expand Down Expand Up @@ -86,7 +89,7 @@ class Configuration
public function __construct(ServerRequestInterface $request, AbstractModule $module)
{
$this->request = $request;
$this->module = $module;
$this->module = $module;
}

/**
Expand Down
45 changes: 22 additions & 23 deletions src/Facade/DataFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file is part of the package magicsunday/webtrees-descendants-chart.
*
* For the full copyright and license information, please read the
* LICENSE file distributed with this source code.
* LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);
Expand Down Expand Up @@ -63,6 +63,7 @@ class DataFacade
public function setModule(ModuleCustomInterface $module): DataFacade
{
$this->module = $module;

return $this;
}

Expand All @@ -74,6 +75,7 @@ public function setModule(ModuleCustomInterface $module): DataFacade
public function setConfiguration(Configuration $configuration): DataFacade
{
$this->configuration = $configuration;

return $this;
}

Expand All @@ -85,6 +87,7 @@ public function setConfiguration(Configuration $configuration): DataFacade
public function setRoute(string $route): DataFacade
{
$this->route = $route;

return $this;
}

Expand Down Expand Up @@ -152,10 +155,8 @@ private function sortChildrenByBirthdate(RecursiveIteratorIterator $recursiveIte
// Check if each individual in the child list has a valid birthdate
if (
$childrenCollection->every(
static function (Node $nodeData): bool {
return ($nodeData->getData()->getIndividual() !== null)
&& $nodeData->getData()->getIndividual()->getBirthDate()->isOK();
}
static fn (Node $nodeData): bool => ($nodeData->getData()->getIndividual() instanceof Individual)
&& $nodeData->getData()->getIndividual()->getBirthDate()->isOK()
)
) {
$item->setChildren(
Expand All @@ -175,37 +176,35 @@ static function (Node $nodeData): bool {
*/
private function birthDateComparator(): Closure
{
return static function (Node $nodeData1, Node $nodeData2): int {
return Date::compare(
$nodeData1->getData()->getIndividual() !== null
? $nodeData1->getData()->getIndividual()->getEstimatedBirthDate()
: new Date(''),
$nodeData2->getData()->getIndividual() !== null
? $nodeData2->getData()->getIndividual()->getEstimatedBirthDate()
: new Date('')
);
};
return static fn (Node $nodeData1, Node $nodeData2): int => Date::compare(
$nodeData1->getData()->getIndividual() instanceof Individual
? $nodeData1->getData()->getIndividual()->getEstimatedBirthDate()
: new Date(''),
$nodeData2->getData()->getIndividual() instanceof Individual
? $nodeData2->getData()->getIndividual()->getEstimatedBirthDate()
: new Date('')
);
}

/**
* Recursively build the data array of the individual ancestors.
*
* @param null|Individual $individual The start person
* @param Individual|null $individual The start person
* @param int $generation The current generation
*
* @return Node[]
*/
private function buildTreeStructure(?Individual $individual, int $generation = 1): array
{
// Maximum generation reached
if (($individual === null) || ($generation > $this->configuration->getGenerations())) {
if ((!$individual instanceof Individual) || ($generation > $this->configuration->getGenerations())) {
return [];
}

// Get spouse families
$families = $individual->spouseFamilies();

$nodes = [];
$nodes = [];
$nodes[$individual->xref()] = new Node(
$this->getNodeData($generation, $individual)
);
Expand Down Expand Up @@ -273,15 +272,15 @@ private function buildTreeStructure(?Individual $individual, int $generation = 1
* Get the node data required for display the chart.
*
* @param int $generation The generation the person belongs to
* @param null|Individual $individual The current individual
* @param null|Individual $spouse
* @param Individual|null $individual The current individual
* @param Individual|null $spouse
*
* @return NodeData
*/
private function getNodeData(
int $generation,
Individual $individual = null,
Individual $spouse = null
?Individual $individual = null,
?Individual $spouse = null
): NodeData {
// Create a unique ID for each individual
static $id = 0;
Expand All @@ -290,7 +289,7 @@ private function getNodeData(
$treeData->setId(++$id)
->setGeneration($generation);

if ($individual === null) {
if (!$individual instanceof Individual) {
return $treeData;
}

Expand Down
12 changes: 8 additions & 4 deletions src/Model/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* This file is part of the package magicsunday/webtrees-descendants-chart.
*
* For the full copyright and license information; please read the
* LICENSE file distributed with this source code.
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);
Expand Down Expand Up @@ -81,6 +81,7 @@ public function getData(): NodeData
public function setSpouse(int $spouse): Node
{
$this->spouse = $spouse;

return $this;
}

Expand All @@ -92,6 +93,7 @@ public function setSpouse(int $spouse): Node
public function setFamily(int $family): Node
{
$this->family = $family;

return $this;
}

Expand All @@ -111,6 +113,7 @@ public function getChildren(): array
public function setChildren(array $children): Node
{
$this->children = $children;

return $this;
}

Expand All @@ -122,6 +125,7 @@ public function setChildren(array $children): Node
public function addSpouse(int $spouse): Node
{
$this->spouses[] = $spouse;

return $this;
}

Expand All @@ -141,11 +145,11 @@ public function jsonSerialize(): array
$jsonData['spouse'] = $this->spouse;
}

if (count($this->children) > 0) {
if ($this->children !== []) {
$jsonData['children'] = $this->children;
}

if (count($this->spouses) > 0) {
if ($this->spouses !== []) {
$jsonData['spouses'] = $this->spouses;
}

Expand Down
Loading

0 comments on commit c4c11a0

Please sign in to comment.