MarkdownPost::getLatestPosts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Pages;
6
7
use Hyde\Foundation\Kernel\PageCollection;
8
use Hyde\Framework\Features\Blogging\Models\FeaturedImage;
9
use Hyde\Framework\Features\Blogging\Models\PostAuthor;
0 ignored issues
show
Bug introduced by
The type Hyde\Framework\Features\Blogging\Models\PostAuthor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Hyde\Markdown\Contracts\FrontMatter\BlogPostSchema;
11
use Hyde\Pages\Concerns\BaseMarkdownPage;
12
use Hyde\Support\Models\DateString;
13
14
use function array_merge;
15
16
/**
17
 * Page class for Markdown posts.
18
 *
19
 * Markdown posts are stored in the _posts directory and using the .md extension.
20
 * The Markdown will be compiled to HTML using the blog post layout to the _site/posts/ directory.
21
 *
22
 * @see https://hydephp.com/docs/1.x/blog-posts
23
 */
24
class MarkdownPost extends BaseMarkdownPage implements BlogPostSchema
25
{
26
    public static string $sourceDirectory = '_posts';
27
    public static string $outputDirectory = 'posts';
28
    public static string $template = 'hyde::layouts/post';
29
30
    public ?string $description;
31
    public ?string $category;
32
    public ?DateString $date;
33
    public ?PostAuthor $author;
34
    public ?FeaturedImage $image;
35
36
    /** @return \Hyde\Foundation\Kernel\PageCollection<\Hyde\Pages\MarkdownPost> */
37
    public static function getLatestPosts(): PageCollection
38
    {
39
        return static::all()->sortByDesc(function (self $post): int {
40
            return $post->date?->getTimestamp() ?? 0;
0 ignored issues
show
Bug introduced by
The method getTimestamp() does not exist on Hyde\Support\Models\DateString. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
            return $post->date?->/** @scrutinizer ignore-call */ getTimestamp() ?? 0;
Loading history...
41
        });
42
    }
43
44
    public function toArray(): array
45
    {
46
        return array_merge(parent::toArray(), [
47
            'description' => $this->description,
48
            'category' => $this->category,
49
            'date' => $this->date,
50
            'author' => $this->author,
51
            'image' => $this->image,
52
        ]);
53
    }
54
}
55