Conditions | 7 |
Paths | 8 |
Total Lines | 55 |
Code Lines | 25 |
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 |
||
42 | public function handle(DocsImporterManager $manager): void |
||
43 | { |
||
44 | $isForce = $this->option('force'); |
||
45 | $docs = Docs::with('pages')->get(); |
||
|
|||
46 | |||
47 | if ($docs->isEmpty()) { |
||
48 | $this->info('Skipping: No docs provided.'); |
||
49 | |||
50 | return; |
||
51 | } |
||
52 | |||
53 | /** @var Docs $repo */ |
||
54 | foreach ($docs as $repo) { |
||
55 | $importer = $manager->get($repo->importer); |
||
56 | $config = $importer->config($repo->importer_config); |
||
57 | |||
58 | foreach ($importer->files($config) as $file) { |
||
59 | $prefix = '[' . $repo->title . ']::' . $file->getRoute(); |
||
60 | |||
61 | /* |
||
62 | |-------------------------------------------------------------------------- |
||
63 | | Is file with required hash exists? |
||
64 | |-------------------------------------------------------------------------- |
||
65 | */ |
||
66 | $updateRequired = $repo->pages->where('hash', $file->getHash())->isEmpty(); |
||
67 | |||
68 | if (! $updateRequired) { |
||
69 | $this->comment($prefix . ' has no available updates.'); |
||
70 | |||
71 | if (! $isForce) { |
||
72 | continue; |
||
73 | } else { |
||
74 | $this->comment($prefix . ' will force update.'); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | /* |
||
79 | |-------------------------------------------------------------------------- |
||
80 | | Is file with required identifier exists? |
||
81 | |-------------------------------------------------------------------------- |
||
82 | */ |
||
83 | $page = $repo->pages->where('identify', $file->getId())->first(); |
||
84 | |||
85 | $message = $prefix . ' found. Updating sources...'; |
||
86 | |||
87 | if ($page === null) { |
||
88 | $message = $prefix . ' not exists. Uploading new...'; |
||
89 | $page = new DocsPage(['identify' => $file->getId()]); |
||
90 | } |
||
91 | |||
92 | $this->comment($message); |
||
93 | $this->updatePage($repo, $page, $file); |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | |||
119 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: