Conditions | 11 |
Paths | 40 |
Total Lines | 50 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
32 | public function __invoke($path, $manifestDirectory = '') |
||
33 | { |
||
34 | static $manifests = []; |
||
35 | |||
36 | if ( ! Str::startsWith($path, '/')) { |
||
37 | $path = "/{$path}"; |
||
38 | } |
||
39 | |||
40 | if ($manifestDirectory && ! Str::startsWith($manifestDirectory, '/')) { |
||
41 | $manifestDirectory = "/{$manifestDirectory}"; |
||
42 | } |
||
43 | |||
44 | if (file_exists(public_path($manifestDirectory.'/hot'))) { |
||
45 | $url = rtrim(file_get_contents(public_path($manifestDirectory.'/hot'))); |
||
46 | |||
47 | if ('local' !== env('APP_ENV')) { |
||
|
|||
48 | if (Str::startsWith($url, ['http://', 'https://'])) { |
||
49 | return new HtmlString(Str::after($url, ':').$path); |
||
50 | } |
||
51 | |||
52 | return new HtmlString("http://localhost:8080{$path}"); |
||
53 | } |
||
54 | |||
55 | return "http://localhost:8080{$path}"; |
||
56 | } |
||
57 | |||
58 | $manifestPath = public_path($manifestDirectory.'/mix-manifest.json'); |
||
59 | |||
60 | if ( ! isset($manifests[$manifestPath])) { |
||
61 | if ( ! file_exists($manifestPath)) { |
||
62 | throw new Exception('The Mix manifest does not exist.'); |
||
63 | } |
||
64 | |||
65 | $manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true); |
||
66 | } |
||
67 | |||
68 | $manifest = $manifests[$manifestPath]; |
||
69 | |||
70 | if ( ! isset($manifest[$path])) { |
||
71 | $exception = new Exception("Unable to locate Mix file: {$path}."); |
||
72 | |||
73 | if ( ! app('config')->get('app.debug')) { |
||
74 | report($exception); |
||
75 | |||
76 | return $path; |
||
77 | } |
||
78 | throw $exception; |
||
79 | } |
||
80 | |||
81 | return new HtmlString(app('config')->get('app.mix_url').$manifestDirectory.$manifest[$path]); |
||
82 | } |
||
84 |