Completed
Pull Request — master (#116)
by Théo
02:32
created

Requirement::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
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
13
namespace KevinGH\Box\RequirementChecker;
14
15
/**
16
 * The code in this file must be PHP 5.3+ compatible as is used to know if the application can be run.
17
 *
18
 * @private
19
 */
20
final class Requirement
21
{
22
    private $checkIsFulfilled;
23
    private $fulfilled;
24
    private $testMessage;
25
    private $helpText;
26
27
    /**
28
     * @param string $checkIsFulfilled Callable as a string (it will be evaluated with `eval()` returning a `bool` value telling whether the
29
     *                                 requirement is fulfilled or not. The condition is evaluated lazily.
30
     * @param string      $testMessage The message for testing the requirement
31
     * @param string $helpText    The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags)
32
     */
33
    public function __construct(
34
        $checkIsFulfilled,
35
        $testMessage,
36
        $helpText
37
    ) {
38
        $this->checkIsFulfilled = $checkIsFulfilled;
39
        $this->testMessage = (string) $testMessage;
40
        $this->helpText = $helpText;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function isFulfilled()
47
    {
48
        if (null === $this->fulfilled) {
49
            $this->fulfilled = eval($this->checkIsFulfilled);
1 ignored issue
show
introduced by
The use of eval() is discouraged.
Loading history...
50
        }
51
52
        return $this->fulfilled;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getIsFullfilledChecker()
59
    {
60
        return $this->checkIsFulfilled;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getTestMessage()
67
    {
68
        return $this->testMessage;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getHelpText()
75
    {
76
        return $this->helpText;
77
    }
78
}