Conditions | 3 |
Paths | 4 |
Total Lines | 56 |
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 |
||
55 | public function convert(ArticleInterface $article): string |
||
56 | { |
||
57 | $version = $this->versionFactory->create(); |
||
58 | |||
59 | $articleDocument = new ArticleDocument(); |
||
60 | $articleDocument->setTitle($article->getTitle()); |
||
61 | $articleDocument->setIdentifier((string) $article->getId()); |
||
62 | $articleDocument->setLanguage($article->getLocale()); |
||
63 | |||
64 | $components = $this->articleBodyConverter->convert($article->getBody()); |
||
65 | $components = $this->processGalleries($components, $article); |
||
66 | $links = $this->processRelatedArticles($article); |
||
67 | |||
68 | foreach ($components as $component) { |
||
69 | $articleDocument->addComponent($component); |
||
70 | } |
||
71 | |||
72 | $articleDocument->setLayout(new Layout(20, 1024, 20, 60)); |
||
73 | |||
74 | $componentTextStyles = new ComponentTextStyles(); |
||
75 | $componentTextStyles->setDefault(new ComponentTextStyle('#000', 'HelveticaNeue')); |
||
76 | $articleDocument->setComponentTextStyles($componentTextStyles); |
||
77 | |||
78 | $metadata = new Metadata(); |
||
79 | $metadata->setAuthors($article->getAuthorsNames()); |
||
80 | |||
81 | $canonicalUrl = $this->router->generate($article->getRoute()->getRouteName(), [ |
||
82 | 'slug' => $article->getSlug(), |
||
83 | ], RouterInterface::ABSOLUTE_URL); |
||
84 | $metadata->setCanonicalUrl($canonicalUrl); |
||
85 | $metadata->setDateCreated($article->getCreatedAt()); |
||
86 | $metadata->setDatePublished($article->getPublishedAt()); |
||
87 | |||
88 | $metadata->setExcerpt($article->getLead() ?? ''); |
||
89 | |||
90 | $metadata->setGeneratorIdentifier('publisher'); |
||
91 | $metadata->setGeneratorName('Publisher'); |
||
92 | $metadata->setGeneratorVersion($version->getVersion()); |
||
93 | |||
94 | $metadata->setKeywords($article->getKeywordsNames()); |
||
95 | $metadata->setLinks($links); |
||
96 | |||
97 | $featureMedia = $article->getFeatureMedia(); |
||
98 | if (null !== $featureMedia) { |
||
99 | $featureMediaUrl = $this->router->generate('swp_media_get', [ |
||
100 | 'mediaId' => $featureMedia->getImage()->getAssetId(), |
||
101 | 'extension' => $featureMedia->getImage()->getFileExtension(), |
||
102 | ], RouterInterface::ABSOLUTE_URL); |
||
103 | |||
104 | $metadata->setThumbnailURL($featureMediaUrl); |
||
105 | } |
||
106 | |||
107 | $articleDocument->setMetadata($metadata); |
||
108 | |||
109 | return str_replace('"url":', '"URL":', $this->serializer->serialize($articleDocument, 'json')); |
||
110 | } |
||
111 | |||
154 |
This check looks for function calls that miss required arguments.