MoufTwigEnvironmentInstaller2   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 31.25 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 0
cbo 0
dl 15
loc 48
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B install() 15 44 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/*
3
 * Copyright (c) 2013-2015 David Negrier
4
 *
5
 * See the file LICENSE.txt for copying permission.
6
 */
7
8
namespace Mouf\Html\Renderer\Twig;
9
10
use Mouf\Installer\PackageInstallerInterface;
11
use Mouf\MoufManager;
12
use Mouf\Actions\InstallUtils;
13
14
/**
15
 * An installer class
16
 */
17
class MoufTwigEnvironmentInstaller2 implements PackageInstallerInterface
18
{
19
20
    public static function install(MoufManager $moufManager)
21
    {
22
        // Let's create the instances.
23
        $twigLoaderFileSystem = InstallUtils::getOrCreateInstance('twigLoaderFileSystem', 'Twig_Loader_Filesystem', $moufManager);
24
        $twigEnvironment = InstallUtils::getOrCreateInstance('twigEnvironment', 'Mouf\\Html\\Renderer\\Twig\\MoufTwigEnvironment', $moufManager);
25
        $twigDebugExtension = InstallUtils::getOrCreateInstance('twigDebugExtension', 'Twig_Extension_Debug', $moufManager);
26
        $moufTwigExtension = InstallUtils::getOrCreateInstance('moufTwigExtension', 'Mouf\\Html\\Renderer\\Twig\\MoufTwigExtension', $moufManager);
27
        $twigCacheFileSystem = InstallUtils::getOrCreateInstance('twigCacheFileSystem', 'Twig_Cache_Filesystem', $moufManager);
28
29
        // Let's bind instances together.
30
        $twigLoaderFileSystem->getConstructorArgumentProperty('paths')->setValue('return ROOT_PATH;');
31
        $twigLoaderFileSystem->getConstructorArgumentProperty('paths')->setOrigin("php");
32
        
33
        $twigEnvironment->getConstructorArgumentProperty('loader')->setValue($twigLoaderFileSystem);
34
35
36
        $twigEnvironment->getConstructorArgumentProperty('options')->setValue('return array(\'debug\' => DEBUG, \'auto_reload\' => true);');
37
        $twigEnvironment->getConstructorArgumentProperty('options')->setOrigin("php");
38
39
        if (!$twigEnvironment->getSetterProperty('setExtensions')->isValueSet()) {
40
            $twigEnvironment->getSetterProperty('setExtensions')->setValue(array(0 => $moufTwigExtension, 1 => $twigDebugExtension, ));
41
        }
42
        if (!$twigEnvironment->getSetterProperty('setCache')->isValueSet()) {
43
            $twigEnvironment->getSetterProperty('setCache')->setValue($twigCacheFileSystem);
44
        }
45 View Code Duplication
        if (!$moufTwigExtension->getConstructorArgumentProperty('container')->isValueSet()) {
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...
46
            $moufTwigExtension->getConstructorArgumentProperty('container')->setValue('return $container;');
47
            $moufTwigExtension->getConstructorArgumentProperty('container')->setOrigin("php");
48
        }
49 View Code Duplication
        if (!$twigCacheFileSystem->getConstructorArgumentProperty('directory')->isValueSet()) {
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...
50
            $twigCacheFileSystem->getConstructorArgumentProperty('directory')->setValue('// If we are running on a Unix environment, let\'s prepend the cache with the user id of the PHP process.
51
// This way, we can avoid rights conflicts.
52
if (function_exists(\'posix_geteuid\')) {
53
    $posixGetuid = posix_geteuid();
54
} else {
55
    $posixGetuid = \'\';
56
}
57
return rtrim(sys_get_temp_dir(), \'/\\\\\').\'/mouftwigtemplatemain_\'.$posixGetuid.str_replace(":", "", ROOT_PATH);');
58
            $twigCacheFileSystem->getConstructorArgumentProperty('directory')->setOrigin("php");
59
        }
60
61
        // Let's rewrite the MoufComponents.php file to save the component
62
        $moufManager->rewriteMouf();
63
    }
64
}
65