Completed
Pull Request — master (#41)
by Vladimir
02:29
created

PageManager::handleTrackableItem()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 15
nc 3
nop 2
dl 0
loc 24
ccs 16
cts 16
cp 1
crap 3
rs 8.9713
c 2
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Manager;
9
10
use allejo\stakx\Exception\FileAwareException;
11
use allejo\stakx\Exception\TrackedItemNotFoundException;
12
use allejo\stakx\FrontMatter\ExpandedValue;
13
use allejo\stakx\Object\ContentItem;
14
use allejo\stakx\Object\DynamicPageView;
15
use allejo\stakx\Object\JailObject;
16
use allejo\stakx\Object\PageView;
17
use allejo\stakx\Object\RepeaterPageView;
18
use allejo\stakx\System\FileExplorer;
19
use allejo\stakx\System\Folder;
20
use Twig_Error_Syntax;
21
use Twig_Template;
22
23
/**
24
 * This class is responsible for handling all of the PageViews within a website.
25
 *
26
 * PageManager will parse all available dynamic and static PageViews. After, dynamic PageViews will be prepared by
27
 * setting the appropriate values for each ContentItem such as permalinks. Lastly, this class will compile all of the
28
 * PageViews and write them to the target directory.
29
 *
30
 * @package allejo\stakx\Manager
31
 */
32
class PageManager extends TrackingManager
33
{
34
    /**
35
     * The relative (to the stakx project) file path to the redirect template
36
     *
37
     * @var string|bool
38
     */
39
    private $redirectTemplate;
40
41
    /**
42
     * @var PageView[]
43
     */
44
    private $twigExtendsDeps;
45
46
    /**
47
     * @var ContentItem[][]
48
     */
49
    private $collections;
50
51
    /**
52
     * @var Folder
53
     */
54
    private $targetDir;
55
56
    /**
57
     * @var PageView[]
58
     */
59
    private $flatPages;
60
61
    /**
62
     * @var array
63
     */
64
    private $twigOpts;
65
66
    /**
67
     * @var \Twig_Environment
68
     */
69
    private $twig;
70
71
    /**
72
     * PageManager constructor
73
     */
74 2
    public function __construct()
75
    {
76 2
        parent::__construct();
77
78 2
        $this->redirectTemplate = false;
79 2
        $this->twigExtendsDeps = array();
80 2
        $this->collections = array();
81 2
        $this->flatPages = array();
82 2
    }
83
84
    /**
85
     * Give this manager the collections we'll be using for dynamic PageViews
86
     *
87
     * @param ContentItem[][] $collections
88
     */
89 2
    public function setCollections (&$collections)
90
    {
91 2
        $this->collections = &$collections;
92 2
    }
93
94
    /**
95
     * Set the template used for redirects
96
     *
97
     * @param false|string $filePath The path to the redirect template
98
     */
99
    public function setRedirectTemplate ($filePath)
100
    {
101
        $this->redirectTemplate = $filePath;
102
    }
103
104
    /**
105
     * The location where the compiled website will be written to
106
     *
107
     * @param Folder $folder The relative target directory as specified from the configuration file
108
     */
109 2
    public function setTargetFolder (&$folder)
110
    {
111 2
        $this->targetDir = &$folder;
112 2
    }
113
114 2
    public function configureTwig ($configuration, $options)
115
    {
116 2
        $this->twigOpts['configuration'] = $configuration;
117 2
        $this->twigOpts['options']       = $options;
118
119 2
        $this->createTwigManager();
120 2
    }
121
122
    public function getStaticPages ()
123
    {
124
        return $this->flatPages;
125
    }
126
127 1 View Code Duplication
    public function getJailedStaticPages ()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129 1
        $jailedObjects = array();
130
131 1
        foreach ($this->flatPages as $key => $value)
132
        {
133
            // If it's an array, it means the parent is hidden from the site menu therefore its children should be too
134 1
            if (is_array($value))
135 1
            {
136
                continue;
137
            }
138
139 1
            $jailedObjects[$key] = $value->createJail();
140 1
        }
141
142 1
        return $jailedObjects;
143
    }
144
145
    /**
146
     * Go through all of the PageView directories and create a respective PageView for each and classify them as a
147
     * dynamic or static PageView.
148
     *
149
     * @param $pageViewFolders
150
     */
151 2
    public function parsePageViews ($pageViewFolders)
152
    {
153 2
        if (empty($pageViewFolders)) { return; }
154
155
        /**
156
         * The name of the folder where PageViews are located
157
         *
158
         * @var $pageViewFolder string
159
         */
160 2
        foreach ($pageViewFolders as $pageViewFolderName)
161
        {
162 2
            $pageViewFolder = $this->fs->absolutePath($pageViewFolderName);
163
164 2
            if (!$this->fs->exists($pageViewFolder))
165 2
            {
166
                continue;
167
            }
168
169 2
            $this->scanTrackableItems($pageViewFolder, array(
170
                'fileExplorer' => FileExplorer::INCLUDE_ONLY_FILES
171 2
            ), array('/.html$/', '/.twig$/'));
172 2
            $this->saveFolderDefinition($pageViewFolderName);
173 2
        }
174 2
    }
175
176
    /**
177
     * Compile dynamic and static PageViews
178
     */
179 2
    public function compileAll ()
180
    {
181 2
        foreach (array_keys($this->trackedItemsFlattened) as $filePath)
182
        {
183 2
            $this->compileFromFilePath($filePath);
184 2
        }
185 2
    }
186
187
    public function compileSome ($filter = array())
188
    {
189
        /** @var PageView $pageView */
190
        foreach ($this->trackedItemsFlattened as $pageView)
191
        {
192
            if ($pageView->hasTwigDependency($filter['namespace'], $filter['dependency']))
193
            {
194
                $this->compilePageView($pageView);
195
            }
196
        }
197
    }
198
199
    /**
200
     * @param ContentItem $contentItem
201
     */
202
    public function compileContentItem (&$contentItem)
203
    {
204
        $pageView = $contentItem->getPageView();
205
206
        // This ContentItem doesn't have an individual PageView dedicated to displaying this item
207
        if (is_null($pageView))
208
        {
209
            return;
210
        }
211
212
        $template = $this->createTemplate($pageView);
213
        $contentItem->evaluateFrontMatter(
214
            $pageView->getFrontMatter(false)
215
        );
216
217
        $output = $template->render(array(
218
            'this' => $contentItem
219
        ));
220
221
        $this->targetDir->writeFile($contentItem->getTargetFile(), $output);
222
    }
223
224
    /**
225
     * Add a new ContentItem to the respective parent PageView of the ContentItem
226
     *
227
     * @param ContentItem $contentItem
228
     */
229
    public function updatePageView ($contentItem)
230
    {
231
        /** @var DynamicPageView $pageView */
232
        foreach ($this->trackedItems['dynamic'] as &$pageView)
233
        {
234
            $fm = $pageView->getFrontMatter(false);
235
236
            if ($fm['collection'] == $contentItem->getCollection())
237
            {
238
                $pageView->addContentItem($contentItem);
239
            }
240
        }
241
    }
242
243
    /**
244
     * Update an existing Twig variable that's injected globally
245
     *
246
     * @param string $variable
247
     * @param string $value
248
     */
249
    public function updateTwigVariable ($variable, $value)
250
    {
251
        $this->twig->addGlobal($variable, $value);
252
    }
253
254
    /**
255
     * {@inheritdoc}
256
     */
257 2
    public function isTracked($filePath)
258
    {
259 2
        return (parent::isTracked($filePath) || isset($this->twigExtendsDeps[$filePath]));
260
    }
261
262
    /**
263
     * {@inheritdoc}
264
     */
265 2
    public function refreshItem($filePath)
266
    {
267
        if (parent::isTracked($filePath))
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (isTracked() instead of refreshItem()). Are you sure this is correct? If so, you might want to change this to $this->isTracked().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
268
        {
269
            $this->compileFromFilePath($filePath);
270
271
            return;
272
        }
273
274
        $this->createTwigManager();
275
276 2
        foreach ($this->twigExtendsDeps[$filePath] as $pageView)
0 ignored issues
show
Bug introduced by
The expression $this->twigExtendsDeps[$filePath] of type object<allejo\stakx\Object\PageView> is not traversable.
Loading history...
277
        {
278
            $this->compilePageView($pageView);
279
        }
280
    }
281
282
    /**
283
     * {@inheritdoc}
284
     */
285 2
    protected function handleTrackableItem($filePath, $options = array())
286
    {
287 2
        $pageView  = PageView::create($filePath);
288 2
        $namespace = $pageView->getType();
289
290
        switch ($namespace)
291
        {
292 2
            case PageView::DYNAMIC_TYPE:
293 2
                $this->handleTrackableDynamicPageView($pageView);
0 ignored issues
show
Compatibility introduced by
$pageView of type object<allejo\stakx\Object\PageView> is not a sub-type of object<allejo\stakx\Object\DynamicPageView>. It seems like you assume a child class of the class allejo\stakx\Object\PageView to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
294 2
                break;
295
296 2
            case PageView::STATIC_TYPE:
297 2
                $this->handleTrackableStaticPageView($pageView);
298 2
                break;
299
300 2
            default:
301 2
                break;
302 2
        }
303
304 2
        $this->addObjectToTracker($pageView, $pageView->getRelativeFilePath(), $namespace);
305 2
        $this->saveTrackerOptions($pageView->getRelativeFilePath(), array(
306
            'viewType' => $namespace
307 2
        ));
308 2
    }
309
310
    /**
311
     * @param DynamicPageView $pageView
312
     */
313 2
    private function handleTrackableDynamicPageView ($pageView)
314
    {
315 2
        $frontMatter = $pageView->getFrontMatter(false);
316 2
        $collection = $frontMatter['collection'];
317
318 2
        if (!isset($this->collections[$collection]))
319 2
        {
320
            throw new \RuntimeException("The '$collection' collection is not defined");
321
        }
322
323 2
        foreach ($this->collections[$collection] as &$item)
324
        {
325 2
            $item->evaluateFrontMatter($frontMatter);
326 2
            $pageView->addContentItem($item);
327 2
        }
328 2
    }
329
330
    /**
331
     * @param PageView $pageView
332
     */
333 2
    private function handleTrackableStaticPageView ($pageView)
334
    {
335 2
        if (empty($pageView['title'])) { return; }
336
337 2
        $this->flatPages[$pageView['title']] = $pageView;
338 2
    }
339
340
    /**
341
     * Create a Twig environment
342
     */
343 2
    private function createTwigManager ()
344
    {
345 2
        $twig = new TwigManager();
346 2
        $twig->configureTwig(
347 2
            $this->twigOpts['configuration'],
348 2
            $this->twigOpts['options']
349 2
        );
350
351 2
        $this->twig = TwigManager::getInstance();
352 2
    }
353
354
    /**
355
     * Compile a given PageView
356
     *
357
     * @param string $filePath The file path to the PageView to compile
358
     *
359
     * @throws \Exception
360
     */
361 2
    private function compileFromFilePath ($filePath)
362
    {
363 2
        if (!$this->isTracked($filePath))
364 2
        {
365
            throw new TrackedItemNotFoundException('PageView not found');
366
        }
367
368
        /** @var DynamicPageView|PageView|RepeaterPageView $pageView */
369 2
        $pageView = &$this->trackedItemsFlattened[$filePath];
370
371
        try
372
        {
373 2
            $pageView->refreshFileContent();
374 2
            $this->compilePageView($pageView);
375
        }
376 2
        catch (\Exception $e)
377
        {
378
            throw FileAwareException::castException($e, $filePath);
379
        }
380 2
    }
381
382
    /**
383
     * @param DynamicPageView|RepeaterPageView|PageView $pageView
384
     */
385 2
    private function compilePageView ($pageView)
386
    {
387 2
        switch ($pageView->getType())
388
        {
389 2
            case PageView::REPEATER_TYPE:
390 2
                $this->compileRepeaterPageView($pageView);
0 ignored issues
show
Compatibility introduced by
$pageView of type object<allejo\stakx\Object\PageView> is not a sub-type of object<allejo\stakx\Object\RepeaterPageView>. It seems like you assume a child class of the class allejo\stakx\Object\PageView to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
391 2
                $this->compileExpandedRedirects($pageView);
392 2
                break;
393
394 2
            case PageView::DYNAMIC_TYPE:
395 2
                $this->compileDynamicPageView($pageView);
396 2
                $this->compileNormalRedirects($pageView);
397 2
                break;
398
399 2
            case PageView::STATIC_TYPE:
400 2
                $this->compileStaticPageView($pageView);
401 2
                $this->compileNormalRedirects($pageView);
402 2
                break;
403 2
        }
404 2
    }
405
406
    /**
407
     * @param RepeaterPageView $pageView
408
     */
409 2
    private function compileRepeaterPageView (&$pageView)
410
    {
411 2
        $template = $this->createTemplate($pageView);
412 2
        $pageView->rewindPermalink();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class allejo\stakx\Object\PageView as the method rewindPermalink() does only exist in the following sub-classes of allejo\stakx\Object\PageView: allejo\stakx\Object\RepeaterPageView. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
413
414 2
        foreach ($pageView->getRepeaterPermalinks() as $permalink)
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class allejo\stakx\Object\PageView as the method getRepeaterPermalinks() does only exist in the following sub-classes of allejo\stakx\Object\PageView: allejo\stakx\Object\RepeaterPageView. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
415
        {
416 2
            $pageView->bumpPermalink();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class allejo\stakx\Object\PageView as the method bumpPermalink() does only exist in the following sub-classes of allejo\stakx\Object\PageView: allejo\stakx\Object\RepeaterPageView. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
417 2
            $pageView->setFrontMatter(array(
418 2
                'permalink' => $permalink->getEvaluated(),
419 2
                'iterators' => $permalink->getIterators()
420 2
            ));
421
422 2
            $output = $template->render(array(
423 2
                'this' => $pageView->createJail()
424 2
            ));
425
426 2
            $this->output->notice("Writing repeater file: {file}", array('file' => $pageView->getTargetFile()));
427 2
            $this->targetDir->writeFile($pageView->getTargetFile(), $output);
428 2
        }
429 2
    }
430
431
    /**
432
     * @param PageView $pageView
433
     */
434 2
    private function compileDynamicPageView (&$pageView)
435
    {
436 2
        $template = $this->createTemplate($pageView);
437
438 2
        $pageViewFrontMatter = $pageView->getFrontMatter(false);
439 2
        $collection = $pageViewFrontMatter['collection'];
440
441 2
        if (!isset($this->collections[$collection]))
442 2
        {
443
            throw new \RuntimeException("The '$collection' collection is not defined");
444
        }
445
446
        /** @var ContentItem $contentItem */
447 2
        foreach ($this->collections[$collection] as &$contentItem)
448
        {
449 2
            $output = $template->render(array(
450 2
                'this' => $contentItem->createJail()
451 2
            ));
452
453 2
            $this->output->notice("Writing file: {file}", array('file' => $contentItem->getTargetFile()));
454 2
            $this->targetDir->writeFile($contentItem->getTargetFile(), $output);
455 2
        }
456 2
    }
457
458
    /**
459
     * @param PageView $pageView
460
     */
461 2
    private function compileStaticPageView (&$pageView)
462
    {
463 2
        $this->twig->addGlobal('__currentTemplate', $pageView->getFilePath());
464
465 2
        $template = $this->createTemplate($pageView);
466 2
        $output = $template->render(array(
467 2
            'this' => $pageView->createJail()
468 2
        ));
469
470 2
        $this->output->notice("Writing file: {file}", array('file' => $pageView->getTargetFile()));
471 2
        $this->targetDir->writeFile($pageView->getTargetFile(), $output);
472 2
    }
473
474
    /**
475
     * @param DynamicPageView|PageView $pageView
476
     */
477 2
    private function compileNormalRedirects (&$pageView)
478
    {
479 2
        foreach ($pageView->getRedirects() as $redirect)
0 ignored issues
show
Bug introduced by
The expression $pageView->getRedirects() of type null|array<integer,string> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
480
        {
481
            $redirectPageView = PageView::createRedirect(
482
                $redirect,
483
                $pageView->getPermalink(),
484
                $this->redirectTemplate
485
            );
486
487
            $this->compilePageView($redirectPageView);
488 2
        }
489 2
    }
490
491
    /**
492
     * @param RepeaterPageView $pageView
493
     */
494 2
    private function compileExpandedRedirects (&$pageView)
495 1
    {
496 2
        $permalinks = $pageView->getRepeaterPermalinks();
497
498
        /** @var ExpandedValue[] $repeaterRedirect */
499 2
        foreach ($pageView->getRepeaterRedirects() as $repeaterRedirect)
500
        {
501
            /**
502
             * @var int           $index
503
             * @var ExpandedValue $redirect
504
             */
505
            foreach ($repeaterRedirect as $index => $redirect)
506
            {
507
                $redirectPageView = PageView::createRedirect(
508
                    $redirect->getEvaluated(),
509
                    $permalinks[$index]->getEvaluated(),
510
                    $this->redirectTemplate
511
                );
512
513
                $this->compilePageView($redirectPageView);
514
            }
515 2
        }
516 2
    }
517
518
    /**
519
     * @param PageView $pageView
520
     *
521
     * @return Twig_Template
522
     * @throws Twig_Error_Syntax
523
     */
524 2
    private function createTemplate (&$pageView)
525
    {
526
        try
527
        {
528 2
            $template = $this->twig->createTemplate($pageView->getContent());
529
530 2
            $this->trackParentTwigTemplate($template, $pageView);
531
532 2
            return $template;
533
        }
534
        catch (Twig_Error_Syntax $e)
535
        {
536
            $e->setTemplateLine($e->getTemplateLine() + $pageView->getLineOffset());
537
            $e->setTemplateName($pageView->getRelativeFilePath());
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Error::setTemplateName() has been deprecated with message: since 1.29 (to be removed in 2.0). Use setSourceContext() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
538
539
            throw $e;
540
        }
541
    }
542
543
    /**
544
     * Find the parent Twig templates of the given template and keep a list of it
545
     *
546
     * @param Twig_Template $template The template created from the PageView's content
547
     * @param PageView      $pageView The PageView that has this content. Used to keep a reference of PageViews
548
     */
549 2
    private function trackParentTwigTemplate ($template, &$pageView)
550
    {
551 2
        if (!$this->tracking) { return; }
552
553
        /** @var Twig_Template $parent */
554
        $parent = $template->getParent(array());
555
556
        while ($parent !== false)
557
        {
558
            $filePath = $this->fs->getRelativePath($parent->getSourceContext()->getPath());
559
560
            $this->twigExtendsDeps[$filePath][(string)$pageView->getFilePath()] = &$pageView;
561
            $parent = $parent->getParent(array());
562
        }
563
    }
564
}