NewsIconExtension::getFilters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Twig;
4
5
use Twig\Extension\AbstractExtension;
6
use Twig\TwigFilter;
7
8
use App\Entity\News;
9
use App\Entity\Community\News as CommunityNews;
10
use App\Entity\Project\News as ProjectNews;
11
12
class NewsIconExtension extends AbstractExtension
13
{
14 9
    public function getFilters(): array
15
    {
16
        return [
17 9
            new TwigFilter('news_icon', [$this, 'newsIconFilter'], [
18 9
                'is_safe' => ['html']
19
            ]),
20
        ];
21
    }
22
    
23
    public function newsIconFilter(News $news, string $size): string
24
    {
25
        return "<i class='{$this->getIconClass($news->getCategory())} {$size}'></i>";
26
    }
27
28
    protected function getIconClass(string $category): string
29
    {
30
        switch($category) {
31
            case CommunityNews::CATEGORY_COMMUNITY_CREATION: return 'fas fa-plus-circle';
32
            case CommunityNews::CATEGORY_NEW_MEMBER: return 'fas fa-user-plus';
33
            case CommunityNews::CATEGORY_NEW_PROJECT: return 'fas fa-paper-plane';
34
            case ProjectNews::CATEGORY_NEW_COMMUNITY: return 'fas fa-users';
35
            case ProjectNews::CATEGORY_NEW_MEMBER: return 'fas fa-user-plus';
36
            case ProjectNews::CATEGORY_NEW_RELEASE: return 'fas fa-rocket';
37
            case ProjectNews::CATEGORY_NEW_REPOSITORY: return 'fas fa-cogs';
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
38
        }
39
    }
40
}