Skip to content

Commit

Permalink
chore: try and make PHPStan happy
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Nov 5, 2024
1 parent 4326eff commit b7626b1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"symfony/var-dumper": "^7.1.5",
"pestphp/pest": "^3.3",
"symfony/var-dumper": "^7.1.6",
"pestphp/pest": "^3.5.1",
"laravel/pint": "^1.18.1",
"phpstan/phpstan": "^1.12.6",
"phpstan/phpstan": "^1.12.7",
"phpstan/extension-installer": "^1.4.3",
"illuminate/support": "^11.27"
"illuminate/support": "^11.30"
},
"config": {
"allow-plugins": {
Expand Down
13 changes: 13 additions & 0 deletions src/Contracts/ProvidesContentName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Phiki\Contracts;

interface ProvidesContentName
{
/**
* Get the name to apply to nested content.
*
* @return string|null
*/
public function getContentName(): ?string;
}
8 changes: 7 additions & 1 deletion src/Grammar/BeginEndPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use Exception;
use Phiki\Contracts\ContainsCapturesInterface;
use Phiki\Contracts\PatternCollectionInterface;
use Phiki\Contracts\ProvidesContentName;
use Phiki\Support\Regex;
use Phiki\Tokenizer;

class BeginEndPattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface
class BeginEndPattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface, ProvidesContentName
{
public function __construct(
public Regex $begin,
Expand All @@ -22,6 +23,11 @@ public function __construct(
public bool $injection = false,
) {}

public function getContentName(): ?string
{
return $this->contentName;
}

public function getPatterns(): array
{
return $this->patterns;
Expand Down
8 changes: 7 additions & 1 deletion src/Grammar/BeginWhilePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use Exception;
use Phiki\Contracts\ContainsCapturesInterface;
use Phiki\Contracts\PatternCollectionInterface;
use Phiki\Contracts\ProvidesContentName;
use Phiki\Support\Regex;
use Phiki\Tokenizer;

class BeginWhilePattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface
class BeginWhilePattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface, ProvidesContentName
{
public function __construct(
public Regex $begin,
Expand All @@ -22,6 +23,11 @@ public function __construct(
public bool $injection = false,
) {}

public function getContentName(): ?string
{
return $this->contentName;
}

public function getPatterns(): array
{
return $this->patterns;
Expand Down
8 changes: 7 additions & 1 deletion src/Grammar/EndPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use Exception;
use Phiki\Contracts\ContainsCapturesInterface;
use Phiki\Contracts\PatternCollectionInterface;
use Phiki\Contracts\ProvidesContentName;
use Phiki\Support\Regex;
use Phiki\Tokenizer;

class EndPattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface
class EndPattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface, ProvidesContentName
{
public function __construct(
public MatchedPattern $begin,
Expand All @@ -21,6 +22,11 @@ public function __construct(
public bool $injection = false,
) {}

public function getContentName(): ?string
{
return $this->contentName;
}

public function getPatterns(): array
{
return $this->patterns;
Expand Down
8 changes: 7 additions & 1 deletion src/Grammar/WhilePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
use Exception;
use Phiki\Contracts\ContainsCapturesInterface;
use Phiki\Contracts\PatternCollectionInterface;
use Phiki\Contracts\ProvidesContentName;
use Phiki\Support\Regex;
use Phiki\Tokenizer;

class WhilePattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface
class WhilePattern extends Pattern implements ContainsCapturesInterface, PatternCollectionInterface, ProvidesContentName
{
public function __construct(
public MatchedPattern $begin,
Expand All @@ -21,6 +22,11 @@ public function __construct(
public bool $injection = false,
) {}

public function getContentName(): ?string
{
return $this->contentName;
}

public function getPatterns(): array
{
return $this->patterns;
Expand Down
13 changes: 7 additions & 6 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Phiki\Contracts\ContainsCapturesInterface;
use Phiki\Contracts\PatternCollectionInterface;
use Phiki\Contracts\ProvidesContentName;
use Phiki\Environment\Environment;
use Phiki\Exceptions\IndeterminateStateException;
use Phiki\Exceptions\UnreachableException;
Expand Down Expand Up @@ -101,7 +102,7 @@ public function tokenizeLine(int $line, string $lineText): void
if ($endIsMatched) {
$this->state->popPattern();

if ($root->contentName) {
if ($root instanceof ProvidesContentName && $root->getContentName() !== null) {
$this->state->popScope();
}
}
Expand Down Expand Up @@ -303,8 +304,8 @@ protected function process(MatchedPattern $matched, int $line, string $lineText)

$endPattern = $matched->pattern->createEndPattern($matched);

if ($matched->pattern->contentName) {
$this->state->pushScope($matched->pattern->contentName);
if ($matched->pattern instanceof ProvidesContentName && $matched->pattern->getContentName() !== null) {
$this->state->pushScope($matched->pattern->getContentName());
}

if ($endPattern->hasPatterns()) {
Expand All @@ -313,7 +314,7 @@ protected function process(MatchedPattern $matched, int $line, string $lineText)
return;
}

if ($matched->pattern->contentName) {
if ($matched->pattern instanceof ProvidesContentName && $matched->pattern->getContentName() !== null) {
$this->state->popScope();
}

Expand Down Expand Up @@ -362,8 +363,8 @@ protected function process(MatchedPattern $matched, int $line, string $lineText)

$whilePattern = $matched->pattern->createWhilePattern($matched);

if ($matched->pattern->contentName) {
$this->state->pushScope($matched->pattern->contentName);
if ($matched->pattern instanceof ProvidesContentName && $matched->pattern->getContentName() !== null) {
$this->state->pushScope($matched->pattern->getContentName());
}

$this->state->pushPattern($whilePattern);
Expand Down

0 comments on commit b7626b1

Please sign in to comment.