Completed
Push — develop ( 373768...b82813 )
by Mike
05:50
created

src/phpDocumentor/Application.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor;
17
18
use phpDocumentor\Event\Dispatcher;
19
use phpDocumentor\Parser\Event\PreFileEvent;
20
use Psr\Log\LoggerInterface;
21
use Psr\Log\LogLevel;
22
use RuntimeException;
23
use Symfony\Component\DependencyInjection\ContainerInterface;
24
25
/**
26
 * Application class for phpDocumentor.
27
 *
28
 * Can be used as bootstrap when the run method is not invoked.
29
 *
30
 * @codeCoverageIgnore too many side-effects and system calls to properly test
31
 */
32
class Application
33
{
34
    public static function VERSION(): string
35
    {
36
        return trim(file_get_contents(__DIR__ . '/../../VERSION'));
37
    }
38
39
    public static function templateDirectory(): string
40
    {
41
        $templateDir = __DIR__ . '/../../data/templates';
42
43
        // when installed using composer the templates are in a different folder
44
        $composerTemplatePath = __DIR__ . '/../../../templates';
45
        if (file_exists($composerTemplatePath)) {
46
            $templateDir = $composerTemplatePath;
47
        }
48
49
        return $templateDir;
50
    }
51
52
    /**
53
     * Initializes all components used by phpDocumentor.
54
     */
55
    public function __construct(LoggerInterface $logger, ContainerInterface $container)
56
    {
57
        $this->defineIniSettings();
58
59
        Dispatcher::getInstance()->addListener(
60
            'parser.file.pre',
61
            function (PreFileEvent $event) use ($logger) {
62
                $logger->log(LogLevel::NOTICE, 'Parsing ' . $event->getFile());
63
            }
64
        );
65
66
        $this->container = $container;
0 ignored issues
show
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
67
    }
68
69
    /**
70
     * Adjust php.ini settings.
71
     *
72
     * @throws RuntimeException
73
     */
74
    protected function defineIniSettings(): void
75
    {
76
        $this->setTimezone();
77
        ini_set('memory_limit', '-1');
78
79
        if (extension_loaded('Zend OPcache') && ini_get('opcache.enable') && ini_get('opcache.enable_cli')) {
80
            if (ini_get('opcache.save_comments')) {
81
                ini_set('opcache.load_comments', '1');
82
            } else {
83
                ini_set('opcache.enable', '0');
84
            }
85
        }
86
87
        if (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.save_comments') === 0) {
88
            throw new RuntimeException('Please enable zend_optimizerplus.save_comments in php.ini.');
89
        }
90
    }
91
92
    /**
93
     * If the timezone is not set anywhere, set it to UTC.
94
     *
95
     * This is done to prevent any warnings being outputted in relation to using
96
     * date/time functions.
97
     *
98
     * @link http://php.net/manual/en/function.date-default-timezone-get.php for more information how PHP determines the
99
     *     default timezone.
100
     */
101
    protected function setTimezone(): void
102
    {
103
        if (false === ini_get('date.timezone')) {
104
            date_default_timezone_set('UTC');
105
        }
106
    }
107
}
108