1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright (c) 2011-present Mediasift Ltd |
5
|
|
|
* All rights reserved. |
6
|
|
|
* |
7
|
|
|
* Redistribution and use in source and binary forms, with or without |
8
|
|
|
* modification, are permitted provided that the following conditions |
9
|
|
|
* are met: |
10
|
|
|
* |
11
|
|
|
* * Redistributions of source code must retain the above copyright |
12
|
|
|
* notice, this list of conditions and the following disclaimer. |
13
|
|
|
* |
14
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
15
|
|
|
* notice, this list of conditions and the following disclaimer in |
16
|
|
|
* the documentation and/or other materials provided with the |
17
|
|
|
* distribution. |
18
|
|
|
* |
19
|
|
|
* * Neither the names of the copyright holders nor the names of his |
20
|
|
|
* contributors may be used to endorse or promote products derived |
21
|
|
|
* from this software without specific prior written permission. |
22
|
|
|
* |
23
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
24
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
25
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
26
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
27
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
28
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
29
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
30
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
31
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
32
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
33
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
* |
36
|
|
|
* @category Libraries |
37
|
|
|
* @package Storyplayer/Cli |
38
|
|
|
* @author Stuart Herbert <[email protected]> |
39
|
|
|
* @copyright 2011-present Mediasift Ltd www.datasift.com |
40
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
41
|
|
|
* @link http://datasift.github.io/storyplayer |
42
|
|
|
*/ |
43
|
|
|
|
44
|
|
|
namespace DataSift\Storyplayer\Cli; |
45
|
|
|
|
46
|
|
|
use Phix_Project\ValidationLib4\Validator; |
47
|
|
|
use Phix_Project\ValidationLib4\ValidationResult; |
48
|
|
|
|
49
|
|
|
class Feature_TestEnvironmentConfigValidator implements Validator |
50
|
|
|
{ |
51
|
|
|
const MSG_NOTVALIDFILENAME = "invalid filename '%value%'; must end in 'Env.php'"; |
52
|
|
|
const MSG_FILENOTFOUND = "test environment file '%value%' not found"; |
53
|
|
|
const MSG_FILENOTREADABLE = "test environment file '%value%' exists, but is not readable; permissions problem?"; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* |
57
|
|
|
* @param mixed $value |
58
|
|
|
* @param ValidationResult $result |
|
|
|
|
59
|
|
|
* @return ValidationResult |
60
|
|
|
*/ |
61
|
|
|
public function validate($value, ValidationResult $result = null) |
62
|
|
|
{ |
63
|
|
|
if ($result === null) { |
64
|
|
|
$result = new ValidationResult($value); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
// to help avoid silly mistakes, test environment config files |
68
|
|
|
// must end in 'Env.php' |
69
|
|
|
if (substr($value, -7) !== 'Env.php') { |
70
|
|
|
$result->addError(static::MSG_NOTVALIDFILENAME); |
71
|
|
|
return $result; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// does the file exist? |
75
|
|
|
if (!file_exists($value)) { |
76
|
|
|
$result->addError(static::MSG_FILENOTFOUND); |
77
|
|
|
return $result; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// can we read it? |
81
|
|
|
if (!is_readable($value)) { |
82
|
|
|
$result->addError(static::MSG_FILENOTREADABLE); |
83
|
|
|
return $result; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// if we get here, all is good |
87
|
|
|
return $result; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.