Passed
Pull Request — master (#116)
by Théo
02:04
created

Requirement   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 54
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestMessage() 0 3 1
A getIsFullfilledChecker() 0 3 1
A getHelpText() 0 3 1
A isFulfilled() 0 7 2
A __construct() 0 8 1
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\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 = $testMessage;
40
        $this->helpText = $helpText;
41
    }
42
43
    public function isFulfilled()
44
    {
45
        if (null === $this->fulfilled) {
46
            $this->fulfilled = eval($this->checkIsFulfilled);
47
        }
48
49
        return (bool) $this->fulfilled;  // Cast to boolean, `(bool)` and `boolval()` are not available in PHP 5.3
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getIsFullfilledChecker()
56
    {
57
        return $this->checkIsFulfilled;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getTestMessage()
64
    {
65
        return $this->testMessage;
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getHelpText()
72
    {
73
        return $this->helpText;
74
    }
75
}
76