Completed
Push — master ( e25986...ffddd1 )
by Craig
07:06
created

ZikulaWorkflowExtension::prepend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\Bundle\WorkflowBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
17
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
19
use Symfony\Component\Finder\Finder;
20
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
21
use Symfony\Component\Workflow;
22
23
/**
24
 * Class ZikulaWorkflowExtension
25
 */
26
class ZikulaWorkflowExtension extends Extension implements PrependExtensionInterface
27
{
28
    private $workflowDirectories = [];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function load(array $configs, ContainerBuilder $container)
34
    {
35
        // unrequired
36
        //$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
        //$loader->load('services.yml');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function prepend(ContainerBuilder $container)
44
    {
45
        // central workflows in the core system are placed in: lib/Zikula/Bundle/CoreBundle/Resources/workflows/
46
        $this->workflowDirectories[] = __DIR__ . '/../Resources/workflows';
47
48
        $rootDirectory = $container->getParameter('kernel.root_dir');
49
50
        // Modules can define their own workflows in: modules/Acme/MyBundle/Resources/workflows/
51
        $this->workflowDirectories[] = $rootDirectory . '/../modules/*/*/Resources/workflows';
52
53
        // also it is possible to define custom workflows (or override existing ones) in: app/Resources/workflows/
54
        $this->workflowDirectories[] = $rootDirectory . '/Resources/workflows';
55
56
        $this->loadWorkflowDefinitions($container);
57
    }
58
59
    /**
60
     * Loads workflow files from given directories.
61
     *
62
     * @param ContainerBuilder $container
63
     *
64
     * @todo replace Finder usage by glob pattern in master branch
65
     * @see http://symfony.com/blog/new-in-symfony-3-3-import-config-files-with-glob-patterns
66
     */
67
    private function loadWorkflowDefinitions(ContainerBuilder $container)
68
    {
69
        try {
70
            $finder = new Finder();
71
            $finder->files()->name('*.yml')->in($this->workflowDirectories);
72 View Code Duplication
            foreach ($finder as $file) {
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...
73
                $loader = new YamlFileLoader($container, new FileLocator($file->getPath()));
74
                $loader->load($file->getFilename());
75
            }
76
77
            $finder = new Finder();
78
            $finder->files()->name('*.xml')->in($this->workflowDirectories);
79 View Code Duplication
            foreach ($finder as $file) {
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...
80
                $loader = new XmlFileLoader($container, new FileLocator($file->getPath()));
81
                $loader->load($file->getFilename());
82
            }
83
        } catch (\InvalidArgumentException $e) {
84
            // no module with a workflow directory exists, ignore
85
        }
86
    }
87
}
88