Test Failed
Push — main ( 2b2a12...672d0a )
by Michiel
06:14
created

TstampCustomFormat::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Task\System;
22
23
use Phing\Exception\BuildException;
24
use Phing\Project;
25
26
class TstampCustomFormat
27
{
28
    /** @var string */
29
    public $propertyName = '';
30
    /** @var string */
31
    public $pattern = '';
32
    /** @var null|string */
33
    public $locale = null;
34
    /** @var null|string */
35
    public $timezone = null;
36
37
    /**
38
     * The property to receive the date/time string in the given pattern.
39
     */
40
    public function setProperty(string $propertyName): void
41
    {
42
        $this->propertyName = $propertyName;
43
    }
44
45
    /**
46
     * The ICU pattern to be used.
47
     *
48
     * @see https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table
49
     */
50
    public function setPattern(string $pattern): void
51
    {
52
        $this->pattern = $pattern;
53
    }
54
55
    /**
56
     * The locale used to create date/time string.
57
     */
58
    public function setLocale(string $locale): void
59
    {
60
        $this->locale = $locale;
61
    }
62
63
    /**
64
     * The timezone used to create date/time string.
65
     */
66
    public function setTimezone(string $timezone): void
67
    {
68
        $this->timezone = $timezone;
69
    }
70
71
    /**
72
     * Validate parameter.
73
     *
74
     * @param TstampTask $tstampTask Reference to parent task
75
     */
76
    public function validate(TstampTask $tstampTask): void
77
    {
78
        if (empty($this->propertyName)) {
79
            throw new BuildException('property attribute must be provided', $tstampTask->getLocation());
80
        }
81
82
        if (empty($this->pattern)) {
83
            throw new BuildException('pattern attribute must be provided', $tstampTask->getLocation());
84
        }
85
86
        if (false !== strpos($this->pattern, '%')) {
87
            $tstampTask->log('pattern attribute must use ICU format https://www.phing.info/guide/chunkhtml/TstampTask.html', Project::MSG_WARN);
88
        }
89
    }
90
}
91