Passed
Branch master (4407aa)
by ANTHONIUS
02:51
created

DoyoUserExtension::loadApiPlatform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * This file is part of the DoyoUserBundle project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
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
declare(strict_types=1);
13
14
namespace Doyo\UserBundle\DependencyInjection;
15
16
use Symfony\Component\Config\ConfigCache;
17
use Symfony\Component\Config\Definition\Processor;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\Config\Resource\FileResource;
20
use Symfony\Component\DependencyInjection\Alias;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Extension\Extension;
23
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
24
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
25
use Symfony\Component\DependencyInjection\Reference;
26
27
class DoyoUserExtension extends Extension implements PrependExtensionInterface
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for class DoyoUserExtension
Loading history...
28
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class DoyoUserExtension
Loading history...
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     * @var array
31
     */
32
    private static $doctrineDrivers = [
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "doctrineDrivers" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "doctrineDrivers" must be prefixed with an underscore
Loading history...
33
        'orm' => [
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 39 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 5 space(s) but found 1
Loading history...
34
            'registry' => 'doctrine',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 18 spaces, but found 12.
Loading history...
35
            'tag'      => 'doctrine.event_subscriber',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 18 spaces, but found 12.
Loading history...
36
        ],
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 17 space(s), but found 8.
Loading history...
37
        'mongodb' => [
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 39 spaces, but found 8.
Loading history...
38
            'registry' => 'doctrine_mongodb',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 22 spaces, but found 12.
Loading history...
39
            'tag'      => 'doctrine_mongodb.odm.event_subscriber',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 22 spaces, but found 12.
Loading history...
40
        ],
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 21 space(s), but found 8.
Loading history...
41
        'couchdb' => [
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 39 spaces, but found 8.
Loading history...
42
            'registry'       => 'doctrine_couchdb',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 22 spaces, but found 12.
Loading history...
43
            'tag'            => 'doctrine_couchdb.event_subscriber',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 22 spaces, but found 12.
Loading history...
44
            'listener_class' => 'Doyo\UserBundle\Bridge\CouchDB\UserListener',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 22 spaces, but found 12.
Loading history...
45
        ],
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 21 space(s), but found 8.
Loading history...
46
    ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 38 space(s), but found 4.
Loading history...
47
48
    public function prepend(ContainerBuilder $container)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Missing doc comment for function prepend()
Loading history...
49
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
50
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end prepend()
Loading history...
51
52 1
    public function load(array $configs, ContainerBuilder $container)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function load()
Loading history...
53
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
54 1
        $processor     = new Processor();
55 1
        $configuration = new Configuration();
56
57 1
        $config = $processor->processConfiguration($configuration, $configs);
58
59 1
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
60
61 1
        $loader->load('util.xml');
62 1
        $loader->load('command.xml');
63
64 1
        $this->loadDbDriver($loader, $container, $config);
65
66 1
        $container->setParameter('doyo_user.user_class', $config['user_class']);
67 1
        $container->setParameter('doyo_user.model_manager_name', $config['model_manager_name']);
68 1
        $container->setParameter('doyo_user.api_platform', $config['api_platform']);
69 1
        $container->setParameter('doyo_user.backend_type_orm', true);
70
71 1
        $container->setAlias('doyo_user.util.email_canonicalizer', $config['service']['email_canonicalizer']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 110 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
72 1
        $container->setAlias('doyo_user.util.username_canonicalizer', $config['service']['username_canonicalizer']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 116 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
73 1
        $container->setAlias('doyo_user.util.password_updater', $config['service']['password_updater']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
74 1
        $container->setAlias('doyo_user.user_manager', $config['service']['user_manager']);
75
76 1
        if ($config['api_platform']) {
77
            $this->loadApiPlatform($container);
78
        }
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end load()
Loading history...
80
81 1
    private function loadDbDriver(XmlFileLoader $loader, ContainerBuilder $container, $config)
0 ignored issues
show
Coding Style introduced by
Private method name "DoyoUserExtension::loadDbDriver" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function loadDbDriver()
Loading history...
82
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
83 1
        if ('custom' !== $config['db_driver']) {
84 1
            if (isset(self::$doctrineDrivers[$config['db_driver']])) {
85 1
                $loader->load('doctrine.xml');
86 1
                $container->setAlias('doyo_user.doctrine_registry', new Alias(self::$doctrineDrivers[$config['db_driver']]['registry'], false));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 144 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
87
            } else {
88
                $loader->load(sprintf('%s.xml', $config['db_driver']));
89
            }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
90 1
            $container->setParameter($this->getAlias().'.backend_type_'.$config['db_driver'], true);
91
        }
92
93 1
        if (isset(self::$doctrineDrivers[$config['db_driver']])) {
94 1
            $definition = $container->getDefinition('doyo_user.object_manager');
95 1
            $definition->setFactory([new Reference('doyo_user.doctrine_registry'), 'getManager']);
96
        }
97
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end loadDbDriver()
Loading history...
98
99
    private function loadApiPlatform($container)
0 ignored issues
show
Coding Style introduced by
Private method name "DoyoUserExtension::loadApiPlatform" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function loadApiPlatform()
Loading history...
100
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
101
        $this->generateApiResourceCache($container);
102
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end loadApiPlatform()
Loading history...
103
104
    private function generateApiResourceCache(ContainerBuilder $container)
0 ignored issues
show
Coding Style introduced by
Private method name "DoyoUserExtension::generateApiResourceCache" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function generateApiResourceCache()
Loading history...
105
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
106
        $dir = __DIR__.'/../Resources/config/api_resources';
107
        if (!is_dir($dir)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
108
            mkdir($dir);
109
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
110
        $path  = $dir.'/User.yaml';
111
        $meta  = $path.'.meta';
112
        $cache = new ConfigCache($path, false);
113
114
        if (!$cache->isFresh() || !is_file($meta)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
115
            $template = __DIR__.'/../Resources/config/template/user-resource.yaml';
116
            $contents = file_get_contents($template);
117
            $contents = strtr($contents, [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
118
                '%doyo_user.user_class%' => $container->getParameter('doyo_user.user_class'),
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 42 spaces, but found 16.
Loading history...
119
            ]);
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 41 space(s), but found 12.
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
120
121
            //file_put_contents($dir.'/user-resource.yaml', $contents, LOCK_EX);
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// file_put_contents($dir.'/user-resource.yaml', $contents, LOCK_EX);" but found "//file_put_contents($dir.'/user-resource.yaml', $contents, LOCK_EX);"
Loading history...
Coding Style Documentation introduced by
Inline comments must start with a capital letter
Loading history...
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
122
            $resources = [new FileResource($template)];
123
            $cache->write($contents, $resources);
124
        }
125
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end generateApiResourceCache()
Loading history...
126
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
127