@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | - * @param $study |
|
| 34 | + * @param Study $study |
|
| 35 | 35 | * @param mixed $control |
| 36 | 36 | * @param Experiment[] $experiments |
| 37 | 37 | * @param string[] $interfaces |
@@ -111,6 +111,9 @@ discard block |
||
| 111 | 111 | return $experiment; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | + /** |
|
| 115 | + * @param string $name |
|
| 116 | + */ |
|
| 114 | 117 | private function createPropertyExperiment($name, Study $study, $control, array $trials) |
| 115 | 118 | { |
| 116 | 119 | $experiment_name = sprintf('%s::$%s', $study->getName(), $name); |
@@ -137,7 +140,7 @@ discard block |
||
| 137 | 140 | /** |
| 138 | 141 | * @param mixed $instance |
| 139 | 142 | * @param string $name |
| 140 | - * @return callable |
|
| 143 | + * @return \Closure |
|
| 141 | 144 | */ |
| 142 | 145 | private function createPropertyCallable($instance, $name) |
| 143 | 146 | { |
@@ -161,6 +164,9 @@ discard block |
||
| 161 | 164 | }; |
| 162 | 165 | } |
| 163 | 166 | |
| 167 | + /** |
|
| 168 | + * @param string $name |
|
| 169 | + */ |
|
| 164 | 170 | private function createMissingMethodCallable($instance, $name) |
| 165 | 171 | { |
| 166 | 172 | return function() use ($instance, $name) { |
@@ -43,15 +43,15 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | array_push($interfaces, Blind::class); |
| 45 | 45 | |
| 46 | - foreach($interfaces as &$interface) { |
|
| 47 | - if(strpos($interface, '\\') !== 0) { |
|
| 48 | - $interface = '\\'.$interface; |
|
| 46 | + foreach ($interfaces as &$interface) { |
|
| 47 | + if (strpos($interface, '\\') !== 0) { |
|
| 48 | + $interface = '\\' . $interface; |
|
| 49 | 49 | } |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $generator = new ClassGenerator($blind_name, 'Scientist\Blind'); |
| 53 | 53 | $generator->setImplementedInterfaces($interfaces); |
| 54 | - $generator->addTrait('\\'.DecoratorTrait::class); |
|
| 54 | + $generator->addTrait('\\' . DecoratorTrait::class); |
|
| 55 | 55 | |
| 56 | 56 | $this->addInterfaceMethods($generator, $interfaces); |
| 57 | 57 | |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $experiments = []; |
| 74 | 74 | $reflection = new ReflectionClass($control); |
| 75 | - foreach($reflection->getMethods() as $method) { |
|
| 75 | + foreach ($reflection->getMethods() as $method) { |
|
| 76 | 76 | $experiments[] = $this->createMethodExperiment($method->getName(), $study, $control, $trials); |
| 77 | 77 | } |
| 78 | - foreach($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
|
| 78 | + foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { |
|
| 79 | 79 | $experiments[] = $this->createPropertyExperiment($property->getName(), $study, $control, $trials); |
| 80 | 80 | } |
| 81 | 81 | return $experiments; |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $experiment->control([$control, $name]); |
| 99 | 99 | |
| 100 | - foreach($trials as $trial_name => $trial) { |
|
| 101 | - if(method_exists($trial, $name)){ |
|
| 100 | + foreach ($trials as $trial_name => $trial) { |
|
| 101 | + if (method_exists($trial, $name)) { |
|
| 102 | 102 | $experiment->trial($trial_name, [$trial, $name]); |
| 103 | 103 | } else { |
| 104 | 104 | $experiment->trial($trial_name, $this->createMissingMethodCallable($trial, $name)); |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $experiment->control($this->createPropertyCallable($control, $name)); |
| 122 | 122 | |
| 123 | - foreach($trials as $trial_name => $trial) { |
|
| 124 | - if(property_exists($trial, $name)){ |
|
| 123 | + foreach ($trials as $trial_name => $trial) { |
|
| 124 | + if (property_exists($trial, $name)) { |
|
| 125 | 125 | $experiment->trial($trial_name, $this->createPropertyCallable($trial, $name)); |
| 126 | 126 | } else { |
| 127 | 127 | $experiment->trial($trial_name, $this->createMissingPropertyCallable($trial, $name)); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | return function() use ($instance, $name) { |
| 145 | 145 | $args = func_get_args(); |
| 146 | 146 | // __set |
| 147 | - if(count($args) > 1) { |
|
| 147 | + if (count($args) > 1) { |
|
| 148 | 148 | list($name, $value) = $args; |
| 149 | 149 | return $instance->{$name} = $value; |
| 150 | 150 | } |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | return call_user_func_array([$experiment, 'run'], $arguments); |
| 177 | 177 | PHP; |
| 178 | 178 | |
| 179 | - foreach($interfaces as $interface) { |
|
| 179 | + foreach ($interfaces as $interface) { |
|
| 180 | 180 | $reflection = new ClassReflection($interface); |
| 181 | - foreach($reflection->getMethods() as $method) { |
|
| 181 | + foreach ($reflection->getMethods() as $method) { |
|
| 182 | 182 | $generator = MethodGenerator::fromReflection($method); |
| 183 | 183 | $generator->setInterface(false); |
| 184 | 184 | $generator->setBody(sprintf($template, $method->getName())); |
@@ -205,7 +205,7 @@ |
||
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | 207 | * @param string ...$interface blind will implement the interfaces specified |
| 208 | - * @return mixed |
|
| 208 | + * @return Blind |
|
| 209 | 209 | */ |
| 210 | 210 | public function blind($interface = null) |
| 211 | 211 | { |
@@ -210,7 +210,7 @@ |
||
| 210 | 210 | public function blind($interface = null) |
| 211 | 211 | { |
| 212 | 212 | $interfaces = func_get_args(); |
| 213 | - if($interface == null) { |
|
| 213 | + if ($interface == null) { |
|
| 214 | 214 | array_shift($interfaces); |
| 215 | 215 | } |
| 216 | 216 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | function __construct(Study $study, array $experiments = []) |
| 49 | 49 | { |
| 50 | 50 | $this->study = $study; |
| 51 | - foreach($experiments as $experiment) { |
|
| 51 | + foreach ($experiments as $experiment) { |
|
| 52 | 52 | $this->experiments[$experiment->getName()] = $experiment; |
| 53 | 53 | } |
| 54 | 54 | } |