Conditions | 6 |
Paths | 10 |
Total Lines | 69 |
Code Lines | 40 |
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 |
||
23 | public function up(Schema $schema): void |
||
24 | { |
||
25 | /** @var PortfolioAttachmentRepository $attachmentRepo */ |
||
26 | $attachmentRepo = $this->container->get(PortfolioAttachmentRepository::class); |
||
|
|||
27 | |||
28 | /** @var PortfolioRepository $itemRepo */ |
||
29 | $itemRepo = $this->container->get(PortfolioRepository::class); |
||
30 | |||
31 | /** @var PortfolioCommentRepository $itemRepo */ |
||
32 | $commentRepo = $this->container->get(PortfolioCommentRepository::class); |
||
33 | |||
34 | $attachmentRows = $this->connection |
||
35 | ->executeQuery('SELECT * FROM portfolio_attachment') |
||
36 | ->fetchAllAssociative() |
||
37 | ; |
||
38 | |||
39 | foreach ($attachmentRows as $attachmentRow) { |
||
40 | $userId = 0; |
||
41 | $resource = null; |
||
42 | $resourceRepo = null; |
||
43 | |||
44 | if (PortfolioAttachment::TYPE_ITEM === (int) $attachmentRow['origin_type']) { |
||
45 | $resourceRepo = $itemRepo; |
||
46 | $resource = $itemRepo->find($attachmentRow['origin_id']); |
||
47 | |||
48 | $itemRow = $this->connection |
||
49 | ->executeQuery("SELECT user_id FROM portfolio WHERE id = {$attachmentRow['origin_id']}") |
||
50 | ->fetchAssociative() |
||
51 | ; |
||
52 | |||
53 | $userId = $itemRow['user_id'] ?? 0; |
||
54 | } elseif (PortfolioAttachment::TYPE_COMMENT === (int) $attachmentRow['origin_type']) { |
||
55 | $resourceRepo = $commentRepo; |
||
56 | $resource = $commentRepo->find($attachmentRow['origin_id']); |
||
57 | |||
58 | $commentRow = $this->connection |
||
59 | ->executeQuery("SELECT author_id FROM portfolio_comment WHERE id = {$attachmentRow['origin_id']}") |
||
60 | ->fetchAssociative() |
||
61 | ; |
||
62 | |||
63 | $userId = $commentRow['author_id'] ?? 0; |
||
64 | } |
||
65 | |||
66 | if (!$resource) { |
||
67 | continue; |
||
68 | } |
||
69 | |||
70 | $folderId = ((string) $userId)[0]; |
||
71 | $path = $attachmentRow['path']; |
||
72 | |||
73 | $filePath = $this->getUpdateRootPath()."/app/upload/users/$folderId/$userId/portfolio_attachments/$path"; |
||
74 | |||
75 | $this->write('MIGRATIONS :: $filePath -- '.$filePath.' ...'); |
||
76 | |||
77 | if (!file_exists($filePath)) { |
||
78 | continue; |
||
79 | } |
||
80 | |||
81 | $this->addLegacyFileToResource( |
||
82 | $filePath, |
||
83 | $resourceRepo, |
||
84 | $resource, |
||
85 | $attachmentRow['origin_id'], |
||
86 | $attachmentRow['filename'], |
||
87 | $attachmentRow['comment'] |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | $this->entityManager->flush(); |
||
92 | } |
||
94 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.