1 | <?php |
||
16 | class ContentParser |
||
17 | { |
||
18 | /** |
||
19 | * Markdown file iterator |
||
20 | * |
||
21 | * @var MarkdownFileIterator |
||
22 | */ |
||
23 | private $markdownFileIterator; |
||
24 | |||
25 | /** |
||
26 | * Content creator |
||
27 | * |
||
28 | * @var ContentCreator |
||
29 | */ |
||
30 | private $contentCreator; |
||
31 | |||
32 | /** |
||
33 | * Markdown document parser |
||
34 | * |
||
35 | * @var MarkdownDocumentParser |
||
36 | */ |
||
37 | private $mdDocumentParser; |
||
38 | |||
39 | /** |
||
40 | * Markdown options |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private $markdownOptions; |
||
45 | |||
46 | /** |
||
47 | * Content path |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | private $contentDir; |
||
52 | |||
53 | /** |
||
54 | * Constructor |
||
55 | * |
||
56 | * @param MarkdownFileIterator $markdownFileIterator |
||
57 | * @param ContentCreator $contentCreator |
||
58 | * @param MarkdownDocumentParser $mdDocumentParser |
||
59 | */ |
||
60 | public function __construct(MarkdownFileIterator $markdownFileIterator, ContentCreator $contentCreator, |
||
69 | |||
70 | public function __invoke() |
||
71 | { |
||
72 | |||
73 | $config = [ |
||
74 | 'src' => [], |
||
75 | 'content_types' => [ |
||
76 | 'blogEntry' => [ |
||
77 | 'all' => [], |
||
78 | 'tags' => [], |
||
79 | ], |
||
80 | ] |
||
81 | ]; |
||
82 | $mdDocumentParser = $this->getMarkdownDocumentParser(); |
||
83 | $contentCreator = $this->getContentCreator(); |
||
84 | foreach ($this->getMarkdownFileIterator() as $file) { |
||
85 | $entry = $contentCreator($mdDocumentParser(file_get_contents($file->getPathname()))); |
||
86 | $config['src'][$entry->getId()] = $this->getRelativePath($file); |
||
87 | if (true === $entry->isDraft()) { |
||
88 | continue; |
||
89 | } |
||
90 | $entryDate = $entry->getCreated()->format('Y-m-d\TH:i:s'); |
||
91 | $config['content_types'][$entry->getType()]['all'][$entryDate] = $entry->getId(); |
||
92 | if ('blogEntry' == $entry->getType()) { |
||
93 | foreach ($entry->getTags() as $tag) { |
||
94 | $config['content_types']['blogEntry']['tags'][$tag->getId()][$entryDate] = $entry->getId(); |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | foreach ($config['content_types'] as $type => $entry) { |
||
99 | $this->sortByDate($config['content_types'][$type]['all']); |
||
100 | } |
||
101 | ksort($config['content_types']['blogEntry']['tags']); |
||
102 | uasort($config['content_types']['blogEntry']['tags'], array($this, 'sortByEntryCountDescending')); |
||
103 | foreach ($config['content_types']['blogEntry']['tags'] as $tag => $entries) { |
||
104 | $this->sortByDate($config['content_types']['blogEntry']['tags'][$tag]); |
||
105 | } |
||
106 | return $config; |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Get markdown file iterator |
||
111 | * |
||
112 | * @return MarkdownFileIterator |
||
113 | */ |
||
114 | public function getMarkdownFileIterator() : MarkdownFileIterator |
||
118 | |||
119 | /** |
||
120 | * Get content creator |
||
121 | * |
||
122 | * @return ContentCreator |
||
123 | */ |
||
124 | public function getContentCreator() : ContentCreator |
||
128 | |||
129 | /** |
||
130 | * Get markdown document parser |
||
131 | * |
||
132 | * @return MarkdownDocumentParser |
||
133 | */ |
||
134 | public function getMarkdownDocumentParser() : MarkdownDocumentParser |
||
138 | |||
139 | /** |
||
140 | * Get markdown option |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | public function getMarkdownOptions() : array |
||
148 | |||
149 | /** |
||
150 | * Sort by date |
||
151 | * |
||
152 | * @param array $config |
||
153 | */ |
||
154 | private function sortByDate(array &$config) |
||
158 | |||
159 | /** |
||
160 | * Get relative path |
||
161 | * |
||
162 | * @param \SplFileInfo $file |
||
163 | * @return string |
||
164 | */ |
||
165 | private function getRelativePath(\SplFileInfo $file) : string |
||
170 | |||
171 | /** |
||
172 | * Sort by entry count descending |
||
173 | * |
||
174 | * @param array $a |
||
|
|||
175 | * @param array $b |
||
176 | * @return number |
||
177 | */ |
||
178 | private function sortByEntryCountDescending(array $configEntryA, array $configEntryB) |
||
185 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.