Completed
Push — master ( 6090d6...edf18c )
by Craig
09:38 queued 03:17
created

ZikulaRequirements::addZikulaPathRequirements()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 20
nc 2
nop 2
dl 0
loc 27
rs 8.8571
c 1
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\CoreInstallerBundle\Util;
13
14
use Symfony\Component\Intl\Exception\MethodArgumentValueNotImplementedException;
15
16
/**
17
 * Portions of this class copied from or inspired by the Symfony Installer (@see https://github.com/symfony/symfony-installer)
18
 * Class ZikulaRequirements
19
 */
20
class ZikulaRequirements
21
{
22
    public $requirementsErrors = [];
23
24
    public function runSymfonyChecks($parameters = [])
25
    {
26
        try {
27
            $path = realpath(__DIR__.'/../../../../../var/SymfonyRequirements.php');
28
            require $path;
29
            $symfonyRequirements = new \SymfonyRequirements();
30
            $this->addZikulaPathRequirements($symfonyRequirements, $parameters);
31
32
            foreach ($symfonyRequirements->getRequirements() as $req) {
33
                if ($helpText = $this->getErrorMessage($req)) {
34
                    $this->requirementsErrors[] = $helpText;
35
                }
36
            }
37
        } catch (MethodArgumentValueNotImplementedException $e) {
1 ignored issue
show
Bug introduced by
The class Symfony\Component\Intl\E...NotImplementedException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
38
            // workaround https://github.com/symfony/symfony-installer/issues/163
39
        }
40
    }
41
42
    protected function getErrorMessage(\Requirement $requirement, $lineSize = 70)
43
    {
44
        if ($requirement->isFulfilled()) {
45
            return;
46
        }
47
        $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.'   ').PHP_EOL;
48
        $errorMessage .= '   > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.'   > ').PHP_EOL;
49
50
        return $errorMessage;
51
    }
52
53
    private function addZikulaPathRequirements(\SymfonyRequirements $symfonyRequirements, $parameters)
54
    {
55
        $src = realpath(__DIR__ . '/../../../../../');
56
        $symfonyRequirements->addRequirement(
57
            is_writable($src . '/app/config'),
58
            'app/config/ directory must be writable',
59
            'Change the permissions of "<strong>app/config/</strong>" directory so that the web server can write into it.'
60
        );
61
        $symfonyRequirements->addRequirement(
62
            is_writable($src . '/app/config/dynamic'),
63
            'app/config/dynamic/ directory must be writable',
64
            'Change the permissions of "<strong>app/config/dynamic/</strong>" directory so that the web server can write into it.'
65
        );
66
        $symfonyRequirements->addRequirement(
67
            is_writable($src . '/' . $parameters['datadir']),
68
            $parameters['datadir'] . '/ directory must be writable',
69
            'Change the permissions of "<strong>' . $parameters['datadir']. '</strong>" directory so that the web server can write into it.'
70
        );
71
        $customParametersPath = $src . '/app/config/custom_parameters.yml';
72
        if (file_exists($customParametersPath)) {
73
            $symfonyRequirements->addRequirement(
74
                is_writable($customParametersPath),
75
                'app/config/custom_parameters.yml file must be writable',
76
                'Change the permissions of "<strong>app/config/custom_parameters.yml</strong>" so that the web server can write into it.'
77
            );
78
        }
79
    }
80
}
81