Skip to content

Commit

Permalink
Merge pull request #2 from sitegeist/task/phpstanLevel8
Browse files Browse the repository at this point in the history
TASK: Raise php stan level to 8
  • Loading branch information
mficzel authored Apr 25, 2024
2 parents f4ac94c + 75d5924 commit 7ecde18
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 23 deletions.
9 changes: 7 additions & 2 deletions Classes/Aspect/LabelForNodeAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\Neos\Domain\Service\ContentContext;
use Sitegeist\ZombieHunt\Domain\ZombieDetector;

#[Flow\Aspect]
Expand All @@ -18,7 +19,7 @@ class LabelForNodeAspect
protected string $zombieLabel;
protected string $zombieToDestroyLabel;

public function injectZombieDetector(ZombieDetector $zombieDetector)
public function injectZombieDetector(ZombieDetector $zombieDetector): void
{
$this->zombieDetector = $zombieDetector;
}
Expand All @@ -38,7 +39,11 @@ public function markZombieNodes(JoinPointInterface $joinPoint): string
$node = $joinPoint->getProxy();
$label = $joinPoint->getAdviceChain()->proceed($joinPoint);

if ($node instanceof NodeInterface && $node->getContext()->isInBackend() && $node->getContext()->getCurrentRenderingMode()->isEdit()) {
if (
$node instanceof NodeInterface
&& $node->getContext() instanceof ContentContext
&& $node->getContext()->isInBackend() && $node->getContext()->getCurrentRenderingMode()->isEdit()
) {
if ($this->zombieDetector->isZombie($node)) {
if ($this->zombieDetector->isZombieThatHasToBeDestroyed($node)) {
$label = $this->zombieToDestroyLabel . ' ' . $label;
Expand Down
17 changes: 8 additions & 9 deletions Classes/Command/ZombieCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ class ZombieCommandController extends CommandController
protected string $zombieLabel;
protected string $zombieToDestroyLabel;

public function injectZombieDetector(ZombieDetector $zombieDetector)
public function injectZombieDetector(ZombieDetector $zombieDetector): void
{
$this->zombieDetector = $zombieDetector;
}

public function injectRootNodeDetector(RootNodeDetector $rootNodeDetector)
public function injectRootNodeDetector(RootNodeDetector $rootNodeDetector): void
{
$this->rootNodeDetector = $rootNodeDetector;
}

public function injectSiteRepository(SiteRepository $siteRepository)
public function injectSiteRepository(SiteRepository $siteRepository): void
{
$this->siteRepository = $siteRepository;
}
Expand All @@ -55,12 +55,11 @@ public function injectSettings(array $settings): void
*/
public function detectCommand(?string $siteNode = null, ?string $dimensionValues = null): void
{
/**
* @var Site[] $sites
*/
if ($siteNode === null) {
/** @var Site[] $sites */
$sites = $this->siteRepository->findAll();
} else {
/** @var Site[] $sites */
$sites = [$this->siteRepository->findOneByNodeName($siteNode)];
}

Expand Down Expand Up @@ -119,12 +118,11 @@ public function detectCommand(?string $siteNode = null, ?string $dimensionValues
*/
public function destroyCommand(?string $siteNode = null, ?string $dimensionValues = null, ?bool $dryrun = false): void
{
/**
* @var Site[] $sites
*/
if ($siteNode === null) {
/** @var Site[] $sites */
$sites = $this->siteRepository->findAll();
} else {
/** @var Site[] $sites */
$sites = [$this->siteRepository->findOneByNodeName($siteNode)];
}

Expand Down Expand Up @@ -205,6 +203,7 @@ private function traverseSubtreeAndYieldZombieNodes(NodeInterface $node): \Gener
protected function renderNodePath(NodeInterface $rootNode, NodeInterface $zombieNode): string
{
$pathParts = [];
/** @var NodeInterface|null $parent */
$parent = $zombieNode->getParent();
while ($parent && $parent->getIdentifier() !== $rootNode->getIdentifier()) {
$pathParts[] = $parent->getLabel();
Expand Down
3 changes: 3 additions & 0 deletions Classes/Domain/RootNodeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class RootNodeDetector
{
use CreateContentContextTrait;

/**
* @param array<string, array<string>> $dimensionValues
*/
public function findRootNode(string $siteNodeName, array $dimensionValues = []): NodeInterface
{
$context = $this->createContentContext('live', $dimensionValues);
Expand Down
32 changes: 22 additions & 10 deletions Classes/Domain/ZombieDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ public function isZombie(NodeInterface $node): bool
return false;
}

$latestAllowedTime = time() - $this->zombificationPeriod;
$lastModification = $node->getNodeData()->getLastModificationDateTime()?->getTimestamp();
$lastPublication = $node->getNodeData()->getLastPublicationDateTime()?->getTimestamp();
$latestAllowedTimestamp = time() - $this->zombificationPeriod;

/** @var \DateTime|null $lastModificationDateTime */
$lastModificationDateTime = $node->getNodeData()->getLastModificationDateTime();
$lastModificationTimestamp = $lastModificationDateTime?->getTimestamp();

/** @var \DateTime|null $lastPublicationDateTime */
$lastPublicationDateTime = $node->getNodeData()->getLastPublicationDateTime();
$lastPublicationTimestamp = $lastPublicationDateTime?->getTimestamp();

if (
($lastModification === null || $lastModification < $latestAllowedTime)
&& ($lastPublication === null || $lastPublication < $latestAllowedTime)
($lastModificationTimestamp === null || $lastModificationTimestamp < $latestAllowedTimestamp)
&& ($lastPublicationTimestamp === null || $lastPublicationTimestamp < $latestAllowedTimestamp)
) {
return true;
}
Expand All @@ -47,14 +53,20 @@ public function isZombieThatHasToBeDestroyed(NodeInterface $node): bool
return false;
}

$latestAllowedTime = time() - $this->zombificationPeriod - $this->destructionPeriod;
$lastModification = $node->getNodeData()->getLastModificationDateTime()?->getTimestamp();
$lastPublication = $node->getNodeData()->getLastPublicationDateTime()?->getTimestamp();
$latestAllowedTimestamp = time() - $this->zombificationPeriod - $this->destructionPeriod;

/** @var \DateTime|null $lastModificationDateTime */
$lastModificationDateTime = $node->getNodeData()->getLastModificationDateTime();
$lastModificationTimestamp = $lastModificationDateTime?->getTimestamp();

/** @var \DateTime|null $lastPublicationDateTime */
$lastPublicationDateTime = $node->getNodeData()->getLastPublicationDateTime();
$lastPublicationTimestamp = $lastPublicationDateTime?->getTimestamp();

if (
$node->isVisible() === false
&& ($lastModification === null || $lastModification < $latestAllowedTime)
&& ($lastPublication === null || $lastPublication < $latestAllowedTime)
&& ($lastModificationTimestamp === null || $lastModificationTimestamp < $latestAllowedTimestamp)
&& ($lastPublicationTimestamp === null || $lastPublicationTimestamp < $latestAllowedTimestamp)
) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Helper/ZombieDetectorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ZombieDetectorHelper implements ProtectedContextAwareInterface
{
protected ZombieDetector $zombieDetector;

public function injectZombieDetector(ZombieDetector $zombieDetector)
public function injectZombieDetector(ZombieDetector $zombieDetector): void
{
$this->zombieDetector = $zombieDetector;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"scripts": {
"fix": ["phpcbf --standard=PSR12 Classes"],
"test:lint": ["phpcs --standard=PSR12 -n Classes"],
"test:stan": ["phpstan analyse Classes"],
"test:stan": ["phpstan analyse --level 8 Classes"],
"test": ["composer install", "composer test:lint", "composer test:stan"]
},
"config": {
Expand Down

0 comments on commit 7ecde18

Please sign in to comment.