Conditions | 4 |
Total Lines | 106 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
27 | private function socket(Request $request) : array |
||
28 | { |
||
29 | /** |
||
30 | * @var SWHClient $http |
||
31 | */ |
||
32 | |||
33 | $http = $this->http; |
||
34 | |||
35 | // -- frame handler |
||
36 | |||
37 | $framing = new Framing($socket = new class($http) implements WSocket { |
||
38 | /** |
||
39 | * @var SWHClient |
||
40 | */ |
||
41 | private $c = null; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | */ |
||
46 | private $v = false; |
||
47 | |||
48 | /** |
||
49 | * anonymous constructor. |
||
50 | * @param SWHClient $c |
||
51 | */ |
||
52 | public function __construct(SWHClient $c) |
||
53 | { |
||
54 | $this->c = $c; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param bool $valid |
||
59 | */ |
||
60 | public function status(bool $valid) : void |
||
61 | { |
||
62 | $this->v = $valid; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return bool |
||
67 | */ |
||
68 | public function valid() : bool |
||
69 | { |
||
70 | return $this->v; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param Frame $frame |
||
75 | */ |
||
76 | public function push(Frame $frame) : void |
||
77 | { |
||
78 | $this->c->push($frame->data(), $frame->code()); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | */ |
||
83 | public function close() : void |
||
84 | { |
||
85 | $this->push(new Frame(pack('n', 1000), WSOpcode::CLOSING)); |
||
86 | } |
||
87 | }); |
||
88 | |||
89 | // -- message event |
||
90 | |||
91 | $http->on('message', static function (SWHClient $c, SWSFrame $f) use ($framing, $socket) { |
||
92 | switch ($f->opcode) { |
||
93 | case WSOpcode::CLOSING: |
||
94 | $socket->status(false); |
||
95 | $framing->message()->close(); |
||
96 | return; |
||
97 | default: |
||
98 | $framing->message()->send(new Frame($f->data, $f->opcode)); |
||
99 | } |
||
100 | }); |
||
101 | |||
102 | $http->on('close', static function (SWHClient $c) use ($framing, $socket) { |
||
103 | $socket->status(false); |
||
104 | $framing->message()->close(); |
||
105 | }); |
||
106 | |||
107 | // -- socket dial |
||
108 | |||
109 | $connector = function ($fn) use ($http, $request) { |
||
110 | $http->upgrade($this->getUriPath($request->getUri()), $fn); |
||
111 | }; |
||
112 | |||
113 | // -- socket resp |
||
114 | |||
115 | $response = function (SWHClient $c) use ($request, $framing, $socket) { |
||
116 | $code = $c->statusCode; |
||
117 | |||
118 | if ($code === 101) { |
||
119 | $socket->status(true); |
||
120 | return $framing; |
||
121 | } |
||
122 | |||
123 | if ($code > 0) { |
||
124 | throw new ErrorResponseException(CodePhrases::resolve($code), $code); |
||
125 | } |
||
126 | |||
127 | $this->throwing($request, $c); |
||
128 | }; |
||
129 | |||
130 | // -- packing |
||
131 | |||
132 | return [$connector, $response]; |
||
133 | } |
||
135 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths