Library::getEras()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gnutix\StarWarsLibrary\Model;
6
7
use Gnutix\Library\Model\Library as BaseLibrary;
8
use Gnutix\StarWarsLibrary\StarWarsLibraryInterface;
9
10
final class Library extends BaseLibrary implements StarWarsLibraryInterface
11
{
12
    /** @var Era[] */
13
    protected array $eras;
14
15
    /**
16
     * @return Era[]
17
     */
18
    public function getEras(): array
19
    {
20
        return $this->eras;
21
    }
22
23
    /**
24
     * @return Book[]
25
     */
26
    public function getBooksByEra(string $eraId): array
27
    {
28
        /** @var Book[] $books */
29
        $books = array_filter($this->getBooks(), static function (Book $book) use ($eraId): bool {
30
            return $book->getChronologicalMarker()->getEra()->getId() === $eraId;
31
        });
32
33
        return $books;
34
    }
35
}
36