Passed
Pull Request — master (#155)
by Théo
02:31
created

RequirementCollection::getIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the box project.
5
 *
6
 * (c) Kevin Herrera <[email protected]>
7
 *     Théo Fidry <[email protected]>
8
 *
9
 * This source file is subject to the MIT license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
namespace _HumbugBox5addf3ce683e7\KevinGH\RequirementChecker;
13
14
use ArrayIterator;
15
use Countable;
16
use IteratorAggregate;
17
use Traversable;
18
/**
19
 * The code in this file must be PHP 5.3+ compatible as is used to know if the application can be run.
20
 *
21
 * @private
22
 */
23
final class RequirementCollection implements \IteratorAggregate, \Countable
24
{
25
    /**
26
     * @var Requirement[]
27
     */
28
    private $requirements = array();
29
    /**
30
     * {@inheritdoc}
31
     *
32
     * @return Requirement[]|Traversable
33
     */
34
    public function getIterator()
35
    {
36
        return new \ArrayIterator($this->requirements);
37
    }
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function count()
42
    {
43
        return \count($this->requirements);
44
    }
45
    /**
46
     * @param Requirement $requirement
47
     */
48
    public function add(\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Requirement $requirement)
49
    {
50
        $this->requirements[] = $requirement;
51
    }
52
    /**
53
     * Adds a mandatory requirement evaluated lazily.
54
     *
55
     * @param string $checkIsFulfilled whether the requirement is fulfilled; This string is will be evaluated with `eval()` because
56
     *                                 PHP does not support the serialization or the export of closures
57
     * @param string $testMessage      The message for testing the requirement
58
     * @param string $helpText         The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
59
     */
60
    public function addRequirement($checkIsFulfilled, $testMessage, $helpText)
61
    {
62
        $this->add(new \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Requirement($checkIsFulfilled, $testMessage, $helpText));
63
    }
64
    /**
65
     * Returns all mandatory requirements.
66
     *
67
     * @return Requirement[]
68
     */
69
    public function getRequirements()
70
    {
71
        return $this->requirements;
72
    }
73
    /**
74
     * Returns the PHP configuration file (php.ini) path.
75
     *
76
     * @return false|string php.ini file path
77
     */
78
    public function getPhpIniPath()
79
    {
80
        return \get_cfg_var('cfg_file_path');
81
    }
82
    /**
83
     * @return bool
84
     */
85
    public function evaluateRequirements()
86
    {
87
        return \array_reduce(
88
            $this->requirements,
89
            /**
90
             * @param bool        $checkPassed
91
             * @param Requirement $requirement
92
             *
93
             * @return bool
94
             */
95
            function ($checkPassed, \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Requirement $requirement) {
96
                return $checkPassed && $requirement->isFulfilled();
97
            },
98
            \true
99
        );
100
    }
101
}
102