Completed
Push — master ( 80d5dd...e32bbf )
by Vladimir
03:02
created

Website::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
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;
9
10
use allejo\stakx\Command\BuildableCommand;
11
use allejo\stakx\Core\StakxLogger;
12
use allejo\stakx\Exception\FileAwareException;
13
use allejo\stakx\Manager\AssetManager;
14
use allejo\stakx\Manager\CollectionManager;
15
use allejo\stakx\Manager\DataManager;
16
use allejo\stakx\Manager\MenuManager;
17
use allejo\stakx\Manager\PageManager;
18
use allejo\stakx\Manager\ThemeManager;
19
use allejo\stakx\Manager\TwigManager;
20
use allejo\stakx\Filesystem\FileExplorer;
21
use allejo\stakx\System\Filesystem;
22
use allejo\stakx\Filesystem\Folder;
23
use allejo\stakx\Twig\StakxTwigTextProfiler;
24
use Highlight\Highlighter;
25
use Kwf\FileWatcher\Event\AbstractEvent;
26
use Kwf\FileWatcher\Event\Create;
27
use Kwf\FileWatcher\Event\Modify;
28
use Kwf\FileWatcher\Event\Move;
29
use Kwf\FileWatcher\Watcher;
30
use Symfony\Component\DependencyInjection\ContainerInterface;
31
32
class Website
33
{
34
    /**
35
     * The location of where the compiled website will be written to.
36
     *
37
     * @var Folder
38
     */
39
    private $outputDirectory;
40
41
    /**
42
     * The main configuration to be used to build the specified website.
43
     *
44
     * @var Configuration
45
     */
46
    private $configuration;
47
48
    /**
49
     * When set to true, the Stakx website will be built without a configuration file.
50
     *
51
     * @var bool
52
     */
53
    private $confLess;
54
55
    /**
56
     * @var StakxLogger
57
     */
58
    private $output;
59
60
    /**
61
     * @var AssetManager
62
     */
63
    private $am;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $am. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
64
65
    /**
66
     * @var CollectionManager
67
     */
68
    private $cm;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $cm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
69
70
    /**
71
     * @var DataManager
72
     */
73
    private $dm;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $dm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
74
75
    /**
76
     * @var Filesystem
77
     */
78
    private $fs;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $fs. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
79
80
    /** @var MenuManager */
81
    private $mm;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $mm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
82
83
    /**
84
     * @var PageManager
85
     */
86
    private $pm;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
87
88
    /**
89
     * @var ThemeManager
90
     */
91
    private $tm;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $tm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
92
93
    /** @var Compiler */
94
    private $compiler;
95
96
    /** @var array */
97
    private $creationQueue;
98
99
    private $container;
100
101
    /**
102
     * Constructor.
103
     */
104
    public function __construct(ContainerInterface $container)
105
    {
106
        $this->container = $container;
107
108
        $this->creationQueue = array();
109
        $this->output = $container->get('logger');
110
        $this->mm = new MenuManager();
111
        $this->fs = new Filesystem();
112
    }
113
114
    /**
115
     * Compile the website.
116
     *
117
     * @param bool $tracking Whether or not to keep track of files as they're compiled to save time in 'watch'
118
     */
119
    public function build($tracking = false)
120
    {
121
        Service::setParameter(BuildableCommand::WATCHING, $tracking);
122
123
        // Configure the environment
124
        $this->createFolderStructure();
125
        $this->configureHighlighter();
126
127
        // Our output directory
128
        $this->outputDirectory = new Folder($this->getConfiguration()->getTargetFolder());
129
        $this->outputDirectory->setTargetDirectory($this->getConfiguration()->getBaseUrl());
130
131
        $this->handleDataItems();
132
        $this->handleCollections();
133
134
        // Handle PageViews
135
        $this->pm = $this->container->get(PageManager::class);
136
        $this->pm->parsePageViews($this->getConfiguration()->getPageViewFolders());
137
138
        // Handle the site's menu
139
        $this->mm->setLogger($this->output);
140
        $this->mm->buildFromPageViews($this->pm->getStaticPageViews());
141
142
        // Configure our Twig environment
143
        $twigGlobals = [
144
            [
145
                'name' => 'data',
146
                'value' => ($this->container->has(DataManager::class)) ?
147
                    $this->container->get(DataManager::class)->getJailedDataItems() : []
148
            ],
149
            [
150
                'name' => 'collections',
151
                'value' => ($this->container->has(CollectionManager::class)) ?
152
                    $this->container->get(CollectionManager::class)->getJailedCollections() : []
153
            ]
154
        ];
155
156
        $twigEnv = new TwigManager();
157
        $twigEnv->configureTwig($this->getConfiguration(), array(
158
            'safe'    => Service::getParameter(BuildableCommand::SAFE_MODE),
159
            'globals' => array_merge(array(
160
                array('name' => 'site', 'value' => $this->getConfiguration()->getConfiguration()),
161
                array('name' => 'menu', 'value' => $this->mm->getSiteMenu()),
162
                array('name' => 'pages', 'value' => $this->pm->getJailedStaticPageViews()),
163
            ), $twigGlobals),
164
        ));
165
166
        $profiler = null;
167
168
        if (Service::getParameter(BuildableCommand::BUILD_PROFILE))
169
        {
170
            $profiler = new \Twig_Profiler_Profile();
171
            TwigManager::getInstance()->addExtension(new \Twig_Extension_Profiler($profiler));
172
        }
173
174
        // Compile everything
175
        $theme = $this->configuration->getTheme();
176
        $this->compiler = new Compiler();
177
        $this->compiler->setLogger($this->output);
178
        $this->compiler->setRedirectTemplate($this->getConfiguration()->getRedirectTemplate());
179
        $this->compiler->setPageViews($this->pm->getPageViews(), $this->pm->getPageViewsFlattened());
0 ignored issues
show
Bug introduced by
$this->pm->getPageViews() cannot be passed to setpageviews() as the parameter $pageViews expects a reference.
Loading history...
Bug introduced by
$this->pm->getPageViewsFlattened() cannot be passed to setpageviews() as the parameter $pageViewsFlattened expects a reference.
Loading history...
180
        $this->compiler->setTargetFolder($this->outputDirectory);
181
        $this->compiler->setThemeName($theme);
182
        $this->compiler->compileAll();
183
184
        if (Service::getParameter(BuildableCommand::BUILD_PROFILE))
185
        {
186
            $dumper = new StakxTwigTextProfiler();
187
            $dumper->setTemplateMappings($this->compiler->getTemplateMappings());
188
            $text = $dumper->dump($profiler);
0 ignored issues
show
Bug introduced by
It seems like $profiler defined by null on line 166 can be null; however, Twig_Profiler_Dumper_Base::dump() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
189
            $this->output->writeln($text);
190
        }
191
192
        // At this point, we are looking at static files to copy over meaning we need to ignore all of the files that
193
        // make up the source of a stakx website
194
        $assetsToIgnore = array_merge(
195
            Configuration::$stakxSourceFiles,
196
            $this->getConfiguration()->getExcludes()
197
        );
198
199
        //
200
        // Theme Management
201
        //
202
        if (!is_null($theme))
203
        {
204
            $this->output->notice("Looking for '${theme}' theme...");
205
206
            $this->tm = new ThemeManager($theme);
207
            $this->tm->configureFinder($this->getConfiguration()->getIncludes(), $assetsToIgnore);
208
            $this->tm->setLogger($this->output);
209
            $this->tm->setFolder($this->outputDirectory);
210
            $this->tm->copyFiles();
211
        }
212
213
        //
214
        // Static file management
215
        //
216
        $this->am = new AssetManager();
217
        $this->am->configureFinder($this->getConfiguration()->getIncludes(), $assetsToIgnore);
218
        $this->am->setLogger($this->output);
219
        $this->am->setFolder($this->outputDirectory);
220
        $this->am->copyFiles();
221
    }
222
223
    public function watch()
224
    {
225
        $this->output->writeln('Building website...');
226
        $this->build(true);
227
        $this->output->writeln(sprintf('Watching %s', getcwd()));
228
229
        $exclusions = array_merge($this->getConfiguration()->getExcludes(), array(
230
            $this->getConfiguration()->getTargetFolder()
231
        ));
232
        $fileExplorer = FileExplorer::create(
233
            getcwd(), $exclusions, $this->getConfiguration()->getIncludes()
234
        );
235
236
        $newWatcher = Watcher::create(getcwd());
237
        $newWatcher
238
            ->setLogger($this->output)
239
            ->setExcludePatterns(array_merge(
240
                $exclusions, FileExplorer::$vcsPatterns, array(Configuration::CACHE_FOLDER)
241
            ))
242
            ->setIterator($fileExplorer->getExplorer())
243
            ->addListener(Create::NAME, function ($e) { $this->watchListenerFunction($e); })
244
            ->addListener(Modify::NAME, function ($e) { $this->watchListenerFunction($e); })
245
            ->addListener(Move::NAME,   function ($e) { $this->watchListenerFunction($e); })
246
        ;
247
248
        $this->output->writeln('Watch started successfully');
249
250
        $newWatcher->start();
251
    }
252
253
    private function watchListenerFunction(AbstractEvent $event)
254
    {
255
        $filePath = $this->fs->getRelativePath($event->filename);
256
257
        try
258
        {
259
            switch ($event::getEventName())
260
            {
261
                case Create::NAME:
262
                    $this->creationWatcher($filePath);
263
                    break;
264
265
                case Modify::NAME:
266
                    $this->modificationWatcher($filePath);
267
                    break;
268
269
                case Move::NAME:
270
                    $newFile = $this->fs->getRelativePath($event->destFilename);
0 ignored issues
show
Bug introduced by
The property destFilename does not seem to exist. Did you mean filename?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
271
272
                    $this->deletionWatcher($filePath);
0 ignored issues
show
Unused Code introduced by
The call to the method allejo\stakx\Website::deletionWatcher() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
273
                    $this->creationWatcher($newFile);
274
                    break;
275
            }
276
        }
277
        catch (FileAwareException $e)
278
        {
279
            $this->output->writeln(sprintf("Your website failed to build with the following error in file '%s': %s",
280
                $e->getPath(),
281
                $e->getMessage()
282
            ));
283
        }
284
        catch (\Exception $e)
285
        {
286
            $this->output->writeln(sprintf('Your website failed to build with the following error: %s',
287
                $e->getMessage()
288
            ));
289
        }
290
    }
291
292
    /**
293
     * @return Configuration
294
     */
295
    public function getConfiguration()
296
    {
297
        return $this->configuration;
298
    }
299
300
    /**
301
     * @param string $configFile
302
     *
303
     * @throws \LogicException
304
     */
305
    public function setConfiguration($configFile)
306
    {
307
        if (!$this->fs->exists($configFile) && !$this->isConfLess())
308
        {
309
            $this->output->error('You are trying to build a website in a directory without a configuration file. Is this what you meant to do?');
310
            $this->output->error("To build a website without a configuration, use the '--no-conf' option");
311
312
            throw new \LogicException('Cannot build a website without a configuration when not in Configuration-less mode');
313
        }
314
315
        if ($this->isConfLess())
316
        {
317
            $configFile = '';
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $configFile. This often makes code more readable.
Loading history...
318
        }
319
320
        $this->configuration = new Configuration();
321
        $this->configuration->setLogger($this->output);
322
        $this->configuration->parse($configFile);
323
324
        Service::setParameter('build.preserveCase', $this->configuration->getConfiguration()['build']['preserveCase']);
325
    }
326
327
    /**
328
     * Get whether or not the website is being built in Configuration-less mode.
329
     *
330
     * @return bool True when being built with no configuration file
331
     */
332
    public function isConfLess()
333
    {
334
        return $this->confLess;
335
    }
336
337
    /**
338
     * Set whether or not the website should be built with a configuration.
339
     *
340
     * @param bool $status True when a website should be built without a configuration
341
     */
342
    public function setConfLess($status)
343
    {
344
        $this->confLess = $status;
345
    }
346
347
    /**
348
     * @param string $filePath
349
     */
350
    private function creationWatcher($filePath, $newlyCreate = true)
351
    {
352
        if ($newlyCreate)
353
        {
354
            $this->output->writeln(sprintf('File creation detected: %s', $filePath));
355
        }
356
357
        if ($this->pm->shouldBeTracked($filePath))
358
        {
359
            try
360
            {
361
                $pageView = $this->pm->createNewItem($filePath);
362
363
                $this->compiler->compilePageView($pageView);
364
365
                unset($this->creationQueue[$filePath]);
366
            }
367
            catch (\Exception $e)
368
            {
369
                $this->creationQueue[$filePath] = true;
370
            }
371
        }
372
        elseif ($this->cm->shouldBeTracked($filePath))
373
        {
374
            try
375
            {
376
                $contentItem = $this->cm->createNewItem($filePath);
377
                TwigManager::getInstance()->addGlobal('collections', $this->cm->getCollections());
378
379
                $this->pm->trackNewContentItem($contentItem);
0 ignored issues
show
Compatibility introduced by
$contentItem of type object<allejo\stakx\Document\TrackableDocument> is not a sub-type of object<allejo\stakx\Document\ContentItem>. It seems like you assume a concrete implementation of the interface allejo\stakx\Document\TrackableDocument 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...
380
                $this->compiler->compileContentItem($contentItem);
0 ignored issues
show
Deprecated Code introduced by
The method allejo\stakx\Compiler::compileContentItem() has been deprecated.

This method has been deprecated.

Loading history...
381
                $this->compiler->compileSome(array(
382
                    'namespace'  => 'collections',
383
                    'dependency' => $contentItem->getNamespace(),
384
                ));
385
386
                unset($this->creationQueue[$filePath]);
387
            }
388
            catch (\Exception $e)
389
            {
390
                $this->creationQueue[$filePath] = true;
391
            }
392
        }
393 View Code Duplication
        elseif ($this->dm->shouldBeTracked($filePath))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
394
        {
395
            $change = $this->dm->createNewItem($filePath);
396
            TwigManager::getInstance()->addGlobal('data', $this->dm->getDataItems());
397
398
            $this->compiler->compileSome(array(
399
                'namespace'  => 'data',
400
                'dependency' => $change,
401
            ));
402
        }
403
        elseif (!is_null($this->tm) && $this->tm->shouldBeTracked($filePath))
404
        {
405
            $this->tm->createNewItem($filePath);
406
        }
407
        elseif ($this->am->shouldBeTracked($filePath))
408
        {
409
            $this->am->createNewItem($filePath);
410
        }
411
    }
412
413
    /**
414
     * @param string $filePath
415
     */
416
    private function modificationWatcher($filePath)
417
    {
418
        $this->output->writeln(sprintf('File change detected: %s', $filePath));
419
420
        if (isset($this->creationQueue[$filePath]))
421
        {
422
            $this->creationWatcher($filePath, false);
423
        }
424
        elseif ($this->compiler->isParentTemplate($filePath))
425
        {
426
            TwigManager::getInstance()->clearTemplateCache();
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Environment::clearTemplateCache() has been deprecated with message: since 1.18.3 (to be removed in 2.0)

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...
427
            $this->compiler->refreshParent($filePath);
428
        }
429
        elseif ($this->compiler->isImportDependency($filePath))
430
        {
431
            TwigManager::getInstance()->clearTemplateCache();
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Environment::clearTemplateCache() has been deprecated with message: since 1.18.3 (to be removed in 2.0)

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...
432
            $this->compiler->compileImportDependencies($filePath);
433
        }
434
        elseif ($this->pm->isTracked($filePath))
435
        {
436
            $change = $this->pm->refreshItem($filePath);
437
438
            TwigManager::getInstance()->clearTemplateCache();
0 ignored issues
show
Deprecated Code introduced by
The method Twig_Environment::clearTemplateCache() has been deprecated with message: since 1.18.3 (to be removed in 2.0)

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...
439
            $this->compiler->compilePageView($change);
440
        }
441
        elseif ($this->cm->isTracked($filePath))
442
        {
443
            $contentItem = &$this->cm->getContentItem($filePath);
444
            $contentItem->refreshFileContent();
445
446
            $this->compiler->compileContentItem($contentItem);
0 ignored issues
show
Deprecated Code introduced by
The method allejo\stakx\Compiler::compileContentItem() has been deprecated.

This method has been deprecated.

Loading history...
447
            $this->compiler->compileSome(array(
448
                'namespace'  => 'collections',
449
                'dependency' => $contentItem->getNamespace(),
450
            ));
451
        }
452 View Code Duplication
        elseif ($this->dm->isTracked($filePath))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
453
        {
454
            $change = $this->dm->refreshItem($filePath);
455
            TwigManager::getInstance()->addGlobal('data', $this->dm->getDataItems());
456
457
            $this->compiler->compileSome(array(
458
                'namespace'  => 'data',
459
                'dependency' => $change,
460
            ));
461
        }
462
        elseif (!is_null($this->tm) && $this->tm->isTracked($filePath))
463
        {
464
            $this->tm->refreshItem($filePath);
465
        }
466
        elseif ($this->am->isTracked($filePath))
467
        {
468
            $this->am->refreshItem($filePath);
469
        }
470
    }
471
472
    /**
473
     * @param string $filePath
474
     */
475
    private function deletionWatcher($filePath)
0 ignored issues
show
Unused Code introduced by
The parameter $filePath is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
476
    {
477
    }
478
479
    /**
480
     * Prepare the Stakx environment by creating necessary cache folders.
481
     */
482
    private function createFolderStructure()
483
    {
484
        $targetDir = $this->fs->absolutePath($this->configuration->getTargetFolder());
485
486
        if (!Service::getParameter(BuildableCommand::NO_CLEAN))
487
        {
488
            $this->fs->remove($targetDir);
489
        }
490
491
        if (!Service::getParameter(BuildableCommand::USE_CACHE))
492
        {
493
            $this->fs->remove($this->fs->absolutePath(Configuration::CACHE_FOLDER, 'twig'));
494
            $this->fs->mkdir($this->fs->absolutePath($this->fs->appendPath(Configuration::CACHE_FOLDER, 'twig')));
495
        }
496
497
        $this->fs->mkdir($targetDir);
498
    }
499
500
    private function configureHighlighter()
501
    {
502
        // Configure our highlighter
503
        Service::setParameter(Configuration::HIGHLIGHTER_ENABLED, $this->getConfiguration()->isHighlighterEnabled());
504
505
        if (Service::getParameter(Configuration::HIGHLIGHTER_ENABLED))
506
        {
507
            foreach ($this->getConfiguration()->getHighlighterCustomLanguages() as $lang => $path)
508
            {
509
                $fullPath = $this->fs->absolutePath($path);
510
511
                if (!$this->fs->exists($fullPath))
512
                {
513
                    $this->output->warning('The following language definition could not be found: {lang}', array(
514
                        'lang' => $path
515
                    ));
516
                    continue;
517
                }
518
519
                Highlighter::registerLanguage($lang, $fullPath);
520
                $this->output->debug('Loading custom language {lang} from {path}...', array(
521
                    'lang' => $lang,
522
                    'path' => $path
523
                ));
524
            }
525
        }
526
    }
527
528
    ///
529
    // Build Process
530
    ///
531
532
    private function handleDataItems()
533
    {
534
        $pm = $this->container->get(PageManager::class);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
535
536
        if (!$this->getConfiguration()->hasDataItems())
537
        {
538
            $this->container->get('logger')->notice('No DataItem folders or Datasets registered... Ignoring');
539
540
            $this->pm->setDatasets([]);
541
542
            return;
543
        }
544
545
        $dm = $this->container->get(DataManager::class);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $dm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
546
        $dm->parseDataItems($this->getConfiguration()->getDataFolders());
547
        $dm->parseDataSets($this->getConfiguration()->getDataSets());
548
549
        $pm->setDatasets($dm->getDataItems());
550
    }
551
552
    private function handleCollections()
553
    {
554
        $pm = $this->container->get(PageManager::class);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $pm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
555
556
        if (!$this->getConfiguration()->hasCollections())
557
        {
558
            $this->container->get('logger')->notice('No Collections registered... Ignoring');
559
560
            $emptyCollections = [];
561
            $pm->setCollections($emptyCollections);
562
563
            return;
564
        }
565
566
        $cm = $this->container->get(CollectionManager::class);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $cm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
567
        $cm->parseCollections($this->getConfiguration()->getCollectionsFolders());
568
569
        $pm->setCollections($cm->getCollections());
570
    }
571
}
572