Conditions | 12 |
Paths | 1 |
Total Lines | 66 |
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 |
||
24 | public function __construct(Shell $__psysh__) |
||
25 | { |
||
26 | $this->setClosure($__psysh__, function () use ($__psysh__) { |
||
27 | // Restore execution scope variables |
||
28 | \extract($__psysh__->getScopeVariables(false)); |
||
|
|||
29 | |||
30 | try { |
||
31 | $__psysh__->getInput(); |
||
32 | |||
33 | try { |
||
34 | // Pull in any new execution scope variables |
||
35 | if ($__psysh__->getLastExecSuccess()) { |
||
36 | \extract($__psysh__->getScopeVariablesDiff(\get_defined_vars())); |
||
37 | } |
||
38 | |||
39 | // Buffer stdout; we'll need it later |
||
40 | \ob_start([$__psysh__, 'writeStdout'], 1); |
||
41 | |||
42 | // Convert all errors to exceptions |
||
43 | \set_error_handler([$__psysh__, 'handleError']); |
||
44 | |||
45 | // Evaluate the current code buffer |
||
46 | $_ = eval($__psysh__->onExecute($__psysh__->flushCode() ?: ExecutionClosure::NOOP_INPUT)); |
||
47 | } catch (\Throwable $_e) { |
||
48 | // Clean up on our way out. |
||
49 | if (\ob_get_level() > 0) { |
||
50 | \ob_end_clean(); |
||
51 | } |
||
52 | |||
53 | throw $_e; |
||
54 | } catch (\Exception $_e) { |
||
55 | // Clean up on our way out. |
||
56 | if (\ob_get_level() > 0) { |
||
57 | \ob_end_clean(); |
||
58 | } |
||
59 | |||
60 | throw $_e; |
||
61 | } finally { |
||
62 | // Won't be needing this anymore |
||
63 | \restore_error_handler(); |
||
64 | } |
||
65 | |||
66 | // Flush stdout (write to shell output, plus save to magic variable) |
||
67 | \ob_end_flush(); |
||
68 | |||
69 | // Save execution scope variables for next time |
||
70 | $__psysh__->setScopeVariables(\get_defined_vars()); |
||
71 | |||
72 | $__psysh__->writeReturnValue($_); |
||
73 | } catch (BreakException $_e) { |
||
74 | $__psysh__->writeException($_e); |
||
75 | |||
76 | return; |
||
77 | } catch (ThrowUpException $_e) { |
||
78 | $__psysh__->writeException($_e); |
||
79 | |||
80 | throw $_e; |
||
81 | } catch (\TypeError $_e) { |
||
82 | $__psysh__->writeException(TypeErrorException::fromTypeError($_e)); |
||
83 | } catch (\Error $_e) { |
||
84 | $__psysh__->writeException(ErrorException::fromError($_e)); |
||
85 | } catch (\Exception $_e) { |
||
86 | $__psysh__->writeException($_e); |
||
87 | } |
||
88 | }); |
||
89 | } |
||
90 | } |
||
91 |