Completed
Push — 1.2-use-project-dir ( 85f5f9 )
by Kamil
83:45 queued 64:09
created

FilesystemRequirements::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 4
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\CoreBundle\Installer\Requirement;
15
16
use Symfony\Component\Translation\TranslatorInterface;
17
18
final class FilesystemRequirements extends RequirementCollection
19
{
20
    /**
21
     * @param TranslatorInterface $translator
22
     * @param string $cacheDir
23
     * @param string $logsDir
24
     * @param string $rootDir Deprecated.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $rootDir not be null|string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
25
     */
26
    public function __construct(TranslatorInterface $translator, string $cacheDir, string $logsDir, string $rootDir = null)
27
    {
28
        parent::__construct($translator->trans('sylius.installer.filesystem.header', []));
29
30
        if (func_num_args() >= 4) {
31
            @trigger_error('Passing root directory to "%s" constructor as a second argument is deprecated since 1.2 and this argument will be removed in 2.0.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
32
33
            [$rootDir, $cacheDir, $logsDir] = [$cacheDir, $logsDir, $rootDir];
34
        }
35
36
        $this
37
            ->add(new Requirement(
38
                $translator->trans('sylius.installer.filesystem.cache.header', []),
39
                is_writable($cacheDir),
40
                true,
41
                $translator->trans('sylius.installer.filesystem.cache.help', ['%path%' => $cacheDir])
42
            ))
43
            ->add(new Requirement(
44
                $translator->trans('sylius.installer.filesystem.logs.header', []),
45
                is_writable($logsDir),
46
                true,
47
                $translator->trans('sylius.installer.filesystem.logs.help', ['%path%' => $logsDir])
48
            ))
49
        ;
50
    }
51
}
52