Completed
Push — master ( 88ab47...b63d85 )
by Craig
05:08
created

PhpHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
c 0
b 0
f 0
dl 0
loc 59
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B setUp() 0 44 6
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\Bundle\CoreInstallerBundle\Helper;
15
16
use Symfony\Contracts\Translation\TranslatorInterface;
17
18
class PhpHelper
19
{
20
    /**
21
     * @var TranslatorInterface
22
     */
23
    private $translator;
24
25
    public function __construct(TranslatorInterface $translator)
26
    {
27
        $this->translator = $translator;
28
    }
29
30
    /**
31
     * Set up PHP for Zikula installation.
32
     */
33
    public function setUp(): array
34
    {
35
        $warnings = [];
36
        if (false === ini_set('default_charset', 'UTF-8')) {
37
            $currentSetting = ini_get('default_charset');
38
            $warnings[] = $this->translator->trans('Could not use %command% to set the %setting% to the value of %requiredValue%. The install or upgrade process may fail at your current setting of %currentValue%.', [
39
                '%command%' => 'ini_set',
40
                '%setting%' => 'default_charset',
41
                '%requiredValue%' => 'UTF-8',
42
                '%currentValue%' => $currentSetting
43
            ]);
44
        }
45
        if (false === mb_regex_encoding('UTF-8')) {
46
            $currentSetting = mb_regex_encoding();
47
            $warnings[] = $this->translator->trans('Could not set %setting% to the value of %requiredValue%. The install or upgrade process may fail at your current setting of %currentValue%.', [
48
                '%setting%' => 'mb_regex_encoding',
49
                '%requiredValue%' => 'UTF-8',
50
                '%currentValue%' => $currentSetting
51
            ]);
52
        }
53
        if (false === ini_set('memory_limit', '128M')) {
54
            $currentSetting = ini_get('memory_limit');
55
            $warnings[] = $this->translator->trans('Could not use %command% to set the %setting% to the value of %requiredValue%. The install or upgrade process may fail at your current setting of %currentValue%.', [
56
                '%command%' => 'ini_set',
57
                '%setting%' => 'memory_limit',
58
                '%requiredValue%' => '128M',
59
                '%currentValue%' => $currentSetting
60
            ]);
61
        }
62
        if (false === ini_set('max_execution_time', '86400')) {
63
            // 86400 = 24 hours
64
            $currentSetting = ini_get('max_execution_time');
65
            if ($currentSetting > 0) {
66
                // 0 = unlimited time
67
                $warnings[] = $this->translator->trans('Could not use %command% to set the %setting% to the value of %requiredValue%. The install or upgrade process may fail at your current setting of %currentValue%.', [
68
                    '%command%' => 'ini_set',
69
                    '%setting%' => 'max_execution_time',
70
                    '%requiredValue%' => '86400',
71
                    '%currentValue%' => $currentSetting
72
                ]);
73
            }
74
        }
75
76
        return $warnings;
77
    }
78
}
79