• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nepada / bust-cache / 6342075144

28 Sep 2023 05:04PM UTC coverage: 95.395% (-3.3%) from 98.726%
6342075144

push

github

xificurk
nepada/phpstan-nette-tester version bump

290 of 304 relevant lines covered (95.39%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/src/Bridges/BustCacheLatte/Nodes/BustCacheNode.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\Bridges\BustCacheLatte\Nodes;
5

6
use Latte\Compiler\NodeHelpers;
7
use Latte\Compiler\Nodes\Php\ExpressionNode;
8
use Latte\Compiler\Nodes\Php\ModifierNode;
9
use Latte\Compiler\Nodes\StatementNode;
10
use Latte\Compiler\PrintContext;
11
use Latte\Compiler\Tag;
12
use Nepada\BustCache\BustCachePathProcessor;
13
use Nepada\BustCache\FileSystem\FileNotFoundException;
14
use Nepada\BustCache\FileSystem\IOException;
15
use Nepada\BustCache\Manifest\InvalidManifestException;
16

17
/**
18
 * {bustCache $file}
19
 * {bustCache dynamic $file}
20
 */
21
final class BustCacheNode extends StatementNode
22
{
23

24
    private readonly ExpressionNode $file;
25

26
    private readonly bool $strictMode;
27

28
    private readonly bool $autoRefresh;
29

30
    private readonly BustCachePathProcessor $bustCachePathProcessor;
31

32
    public function __construct(ExpressionNode $file, bool $strictMode, bool $autoRefresh, BustCachePathProcessor $bustCachePathProcessor)
1✔
33
    {
34
        $this->file = $file;
1✔
35
        $this->strictMode = $strictMode;
1✔
36
        $this->autoRefresh = $autoRefresh;
1✔
37
        $this->bustCachePathProcessor = $bustCachePathProcessor;
1✔
38
    }
1✔
39

40
    public static function create(Tag $tag, bool $strictMode, bool $autoRefresh, BustCachePathProcessor $bustCachePathProcessor): self
1✔
41
    {
42
        $tag->outputMode = $tag::OutputKeepIndentation;
1✔
43
        $tag->expectArguments();
1✔
44
        $autoRefresh = $tag->parser->tryConsumeModifier('dynamic') !== null || $autoRefresh;
1✔
45
        $file = $tag->parser->parseUnquotedStringOrExpression();
1✔
46

47
        return new self($file, $strictMode, $autoRefresh, $bustCachePathProcessor);
1✔
48
    }
49

50
    /**
51
     * @throws IOException
52
     * @throws InvalidManifestException
53
     */
54
    public function print(PrintContext $context): string
1✔
55
    {
56
        // safeUrl is intentionally disabled, we verify the node content represents a valid file path inside BustCachePathProcessor
57
        $modifier = new ModifierNode([], true, false);
1✔
58

59
        if (! $this->autoRefresh) {
1✔
60
            try {
61
                /** @throws \InvalidArgumentException */
62
                $fileValue = NodeHelpers::toValue($this->file, constants: true);
1✔
63
                if (! is_string($fileValue)) {
1✔
64
                    throw new \InvalidArgumentException('File path must be a string');
×
65
                }
66
                $processedPath = $this->bustCachePathProcessor->__invoke($fileValue, true, false);
1✔
67
                return $context->format(
1✔
68
                    'echo %modify(%dump) %line;',
1✔
69
                    $modifier,
70
                    $processedPath,
71
                    $this->position,
1✔
72
                );
73
            } catch (\InvalidArgumentException) { // non-literal file argument used => compile time processing not possible
1✔
74
            } catch (FileNotFoundException) { // missing file => compile time not possible
1✔
75
            }
76
        }
77

78
        return $context->format(
1✔
79
            'echo %modify($this->global->bustCachePathProcessor->__invoke(%node, %dump, %dump)) %line;',
1✔
80
            $modifier,
81
            $this->file,
1✔
82
            $this->strictMode,
1✔
83
            $this->autoRefresh,
1✔
84
            $this->position,
1✔
85
        );
86
    }
87

88
    public function &getIterator(): \Generator
1✔
89
    {
90
        yield $this->file;
1✔
91
    }
1✔
92

93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc