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 23a2024 commit 76f7451
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 76 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ npm run prepare
### Run tests
```
composer update
vendor/bin/phpunit
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
```
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method Fisharebest\\\\Webtrees\\\\Module\\\\ModuleCustomInterface\\:\\:assetUrl\\(\\)\\.$#"
count: 1
path: src/Processor/ImageProcessor.php
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
includes:
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-strict-rules/rules.neon
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-deprecation-rules/rules.neon
# - %currentWorkingDirectory%/phpstan-baseline.neon
- %currentWorkingDirectory%/phpstan-baseline.neon

parameters:
# You can currently choose from 10 levels (0 is the loosest and 9 is the strictest).
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
colors="true"
columns="max"
stderr="true"
bootstrap="./vendor/autoload.php">
bootstrap="./.build/vendor/autoload.php"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
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-fan-chart.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
Expand Down
28 changes: 12 additions & 16 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-fan-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 @@ -45,11 +45,6 @@ class DataFacade
*/
private Configuration $configuration;

/**
* @var string
*/
private string $route;

/**
* @param ModuleCustomInterface $module
*
Expand All @@ -58,6 +53,7 @@ class DataFacade
public function setModule(ModuleCustomInterface $module): DataFacade
{
$this->module = $module;

return $this;
}

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

return $this;
}

Expand All @@ -79,7 +76,6 @@ public function setConfiguration(Configuration $configuration): DataFacade
*/
public function setRoute(string $route): DataFacade
{
$this->route = $route;
return $this;
}

Expand All @@ -88,7 +84,7 @@ public function setRoute(string $route): DataFacade
*
* @param Individual $individual
*
* @return null|Node
* @return Node|null
*/
public function createTreeStructure(Individual $individual): ?Node
{
Expand All @@ -98,23 +94,23 @@ public function createTreeStructure(Individual $individual): ?Node
/**
* 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 null|Node
* @return Node|null
*/
private function buildTreeStructure(?Individual $individual, int $generation = 1): ?Node
{
// Maximum generation reached
if (($individual === null) || ($generation > $this->configuration->getGenerations())) {
if ((!$individual instanceof Individual) || ($generation > $this->configuration->getGenerations())) {
return null;
}

$node = new Node(
$this->getNodeData($generation, $individual)
);

/** @var null|Family $family */
/** @var Family|null $family */
$family = $individual->childFamilies()->first();

if ($family === null) {
Expand All @@ -126,11 +122,11 @@ private function buildTreeStructure(?Individual $individual, int $generation = 1
$motherNode = $this->buildTreeStructure($family->wife(), $generation + 1);

// Add an array of child nodes
if ($fatherNode !== null) {
if ($fatherNode instanceof Node) {
$node->addParent($fatherNode);
}

if ($motherNode !== null) {
if ($motherNode instanceof Node) {
$node->addParent($motherNode);
}

Expand All @@ -140,8 +136,8 @@ 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 int $generation The generation the person belongs to
* @param Individual $individual The current individual
*
* @return NodeData
*/
Expand Down
7 changes: 4 additions & 3 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-fan-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 @@ -60,6 +60,7 @@ public function getData(): NodeData
public function addParent(Node $parent): Node
{
$this->parents[] = $parent;

return $this;
}

Expand All @@ -74,7 +75,7 @@ public function jsonSerialize(): array
'data' => $this->data,
];

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

Expand Down
30 changes: 25 additions & 5 deletions src/Model/NodeData.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-fan-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 @@ -159,7 +159,7 @@ class NodeData implements JsonSerializable
/**
* The underlying individual instance. Only used internally.
*
* @var null|Individual
* @var Individual|null
*/
protected ?Individual $individual = null;

Expand All @@ -179,6 +179,7 @@ public function getId(): int
public function setId(int $id): NodeData
{
$this->id = $id;

return $this;
}

Expand All @@ -190,6 +191,7 @@ public function setId(int $id): NodeData
public function setXref(string $xref): NodeData
{
$this->xref = $xref;

return $this;
}

Expand All @@ -201,6 +203,7 @@ public function setXref(string $xref): NodeData
public function setUrl(string $url): NodeData
{
$this->url = $url;

return $this;
}

Expand All @@ -212,6 +215,7 @@ public function setUrl(string $url): NodeData
public function setUpdateUrl(string $updateUrl): NodeData
{
$this->updateUrl = $updateUrl;

return $this;
}

Expand All @@ -223,6 +227,7 @@ public function setUpdateUrl(string $updateUrl): NodeData
public function setGeneration(int $generation): NodeData
{
$this->generation = $generation;

return $this;
}

Expand All @@ -242,6 +247,7 @@ public function getName(): string
public function setName(string $name): NodeData
{
$this->name = $name;

return $this;
}

Expand All @@ -253,6 +259,7 @@ public function setName(string $name): NodeData
public function setIsNameRtl(bool $isNameRtl): NodeData
{
$this->isNameRtl = $isNameRtl;

return $this;
}

Expand All @@ -264,6 +271,7 @@ public function setIsNameRtl(bool $isNameRtl): NodeData
public function setFirstNames(array $firstNames): NodeData
{
$this->firstNames = $firstNames;

return $this;
}

Expand All @@ -275,6 +283,7 @@ public function setFirstNames(array $firstNames): NodeData
public function setLastNames(array $lastNames): NodeData
{
$this->lastNames = $lastNames;

return $this;
}

Expand All @@ -286,6 +295,7 @@ public function setLastNames(array $lastNames): NodeData
public function setPreferredName(string $preferredName): NodeData
{
$this->preferredName = $preferredName;

return $this;
}

Expand All @@ -297,6 +307,7 @@ public function setPreferredName(string $preferredName): NodeData
public function setAlternativeName(string $alternativeName): NodeData
{
$this->alternativeName = $alternativeName;

return $this;
}

Expand All @@ -308,6 +319,7 @@ public function setAlternativeName(string $alternativeName): NodeData
public function setIsAltRtl(bool $isAltRtl): NodeData
{
$this->isAltRtl = $isAltRtl;

return $this;
}

Expand All @@ -319,6 +331,7 @@ public function setIsAltRtl(bool $isAltRtl): NodeData
public function setThumbnail(string $thumbnail): NodeData
{
$this->thumbnail = $thumbnail;

return $this;
}

Expand All @@ -330,6 +343,7 @@ public function setThumbnail(string $thumbnail): NodeData
public function setSex(string $sex): NodeData
{
$this->sex = $sex;

return $this;
}

Expand All @@ -341,6 +355,7 @@ public function setSex(string $sex): NodeData
public function setBirth(string $birth): NodeData
{
$this->birth = $birth;

return $this;
}

Expand All @@ -352,6 +367,7 @@ public function setBirth(string $birth): NodeData
public function setDeath(string $death): NodeData
{
$this->death = $death;

return $this;
}

Expand All @@ -363,6 +379,7 @@ public function setDeath(string $death): NodeData
public function setMarriageDate(string $marriageDate): NodeData
{
$this->marriageDate = $marriageDate;

return $this;
}

Expand All @@ -374,6 +391,7 @@ public function setMarriageDate(string $marriageDate): NodeData
public function setMarriageDateOfParents(string $marriageDateOfParents): NodeData
{
$this->marriageDateOfParents = $marriageDateOfParents;

return $this;
}

Expand All @@ -385,25 +403,27 @@ public function setMarriageDateOfParents(string $marriageDateOfParents): NodeDat
public function setTimespan(string $timespan): NodeData
{
$this->timespan = $timespan;

return $this;
}

/**
* @return null|Individual
* @return Individual|null
*/
public function getIndividual(): ?Individual
{
return $this->individual;
}

/**
* @param null|Individual $individual
* @param Individual|null $individual
*
* @return NodeData
*/
public function setIndividual(?Individual $individual): NodeData
{
$this->individual = $individual;

return $this;
}

Expand Down

0 comments on commit 76f7451

Please sign in to comment.