Conditions | 3 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | public function configure(ExerciseDispatcher $exerciseDispatcher) |
||
63 | { |
||
64 | $eventDispatcher = $exerciseDispatcher->getEventDispatcher(); |
||
65 | |||
66 | $eventDispatcher->listen('cli.verify.solution-execute.pre', function (CliExecuteEvent $event) { |
||
67 | $event->appendArg('127.0.0.1'); |
||
68 | $event->appendArg($this->getRandomPort()); |
||
69 | }); |
||
70 | |||
71 | $eventDispatcher->listen('cli.verify.user-execute.pre', function (CliExecuteEvent $event) { |
||
72 | $event->appendArg('127.0.0.1'); |
||
73 | $event->appendArg($this->getRandomPort()); |
||
74 | }); |
||
75 | |||
76 | $eventDispatcher->listen('cli.verify.solution.executing', function (CliExecuteEvent $event) { |
||
77 | $args = $event->getArgs()->getArrayCopy(); |
||
78 | $client = $this->socketFactory->createClient(...$args); |
||
79 | |||
80 | //wait for server to boot |
||
81 | usleep(100000); |
||
82 | |||
83 | $client->connect(); |
||
84 | $client->readAll(); |
||
85 | |||
86 | //wait for shutdown |
||
87 | usleep(100000); |
||
88 | }); |
||
89 | |||
90 | $eventDispatcher->insertVerifier('cli.verify.user.executing', function (CliExecuteEvent $event) { |
||
91 | $args = $event->getArgs()->getArrayCopy(); |
||
92 | $client = $this->socketFactory->createClient(...$args); |
||
93 | |||
94 | //wait for server to boot |
||
95 | usleep(100000); |
||
96 | |||
97 | try { |
||
98 | $client->connect(); |
||
99 | } catch (Exception $e) { |
||
100 | return Failure::fromNameAndReason($this->getName(), $e->getMessage()); |
||
101 | } |
||
102 | |||
103 | $out = $client->readAll(); |
||
104 | |||
105 | //wait for shutdown |
||
106 | usleep(100000); |
||
107 | |||
108 | $date = new \DateTime; |
||
109 | |||
110 | //match the current date but any seconds |
||
111 | //since we can't mock time in PHP easily |
||
112 | if (!preg_match(sprintf('/^%s:([0-5][0-9]|60)\n$/', $date->format('Y-m-d H:i')), $out)) { |
||
113 | return new StdOutFailure($this->getName(), $date->format("Y-m-d H:i:s\n"), $out); |
||
114 | } |
||
115 | return new Success($this->getName()); |
||
116 | }); |
||
117 | } |
||
118 | |||
143 |
This check looks for function calls that miss required arguments.