1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Symfony package. |
5
|
|
|
* |
6
|
|
|
* Taken from symfony-docs: contributing/code/standards.rst |
7
|
|
|
* |
8
|
|
|
* (c) Fabien Potencier <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Acme; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Coding standards demonstration. |
18
|
|
|
*/ |
19
|
|
|
class FooBar |
20
|
|
|
{ |
21
|
|
|
const SOME_CONST = 42; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $fooBar; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $dummy Some argument description |
30
|
|
|
*/ |
31
|
|
|
public function __construct($dummy) |
32
|
|
|
{ |
33
|
|
|
$this->fooBar = $this->transformText($dummy); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return string |
38
|
|
|
* |
39
|
|
|
* @deprecated |
40
|
|
|
*/ |
41
|
|
|
public function someDeprecatedMethod() |
42
|
|
|
{ |
43
|
|
|
@trigger_error(sprintf('The %s() method is deprecated since version 2.8 and will be removed in 3.0. Use Acme\Baz::someMethod() instead.', __METHOD__), E_USER_DEPRECATED); |
44
|
|
|
|
45
|
|
|
return Baz::someMethod(); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Transforms the input given as first argument. |
50
|
|
|
* |
51
|
|
|
* @param bool|string $dummy Some argument description |
52
|
|
|
* @param array $options An options collection to be used within the transformation |
53
|
|
|
* |
54
|
|
|
* @return string|null The transformed input |
55
|
|
|
* |
56
|
|
|
* @throws \RuntimeException When an invalid option is provided |
57
|
|
|
*/ |
58
|
|
|
private function transformText($dummy, array $options = []) |
59
|
|
|
{ |
60
|
|
|
$defaultOptions = [ |
61
|
|
|
'some_default' => 'values', |
62
|
|
|
'another_default' => 'more values', |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
foreach ($options as $option) { |
66
|
|
|
if (!in_array($option, $defaultOptions)) { |
67
|
|
|
throw new \RuntimeException(sprintf('Unrecognized option "%s"', $option)); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$mergedOptions = array_merge( |
72
|
|
|
$defaultOptions, |
73
|
|
|
$options |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
if (true === $dummy) { |
77
|
|
|
return null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ('string' === $dummy) { |
81
|
|
|
if ('values' === $mergedOptions['some_default']) { |
82
|
|
|
return substr($dummy, 0, 5); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
return ucwords($dummy); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Performs some basic check for a given value. |
91
|
|
|
* |
92
|
|
|
* @param mixed $value Some value to check against |
93
|
|
|
* @param bool $theSwitch Some switch to control the method's flow |
94
|
|
|
* |
95
|
|
|
* @return bool|void The resultant check if $theSwitch isn't false, void otherwise |
96
|
|
|
*/ |
97
|
|
|
private function reverseBoolean($value = null, $theSwitch = false) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
if (!$theSwitch) { |
100
|
|
|
return; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return !$value; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|