Failed Conditions
Branch feature/refactoring-samurai (8cc7c1)
by Giuliano
03:47
created

ThemeSearch   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 59
rs 10
c 2
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A exists() 0 5 2
A directivefy() 0 3 1
A findOrBuild() 0 7 2
1
<?php
2
3
namespace Maestriam\Samurai\Foundation;
4
5
class ThemeSearch
6
{
7
    
8
9
    /**
10
     * Retorna uma instância de uma diretiva de acordo
11
     * com os dados do nome, do tipo e do tema a qual pertence
12
     *
13
     * @param  string $name Nome da diretiva
14
     * @param  string $type Tipo que pertence
15
     * @return Directive
16
     */
17
    private function directivefy(string $name, string $type) : Directive
0 ignored issues
show
Unused Code introduced by
The method directivefy() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
18
    {
19
        return new Directive($name, $type, $this);
20
    }
21
22
    /**
23
     * Retorna se existe o diretório do tema
24
     * na base de temas
25
     *
26
     * @param  string $name Nome do tema
27
     * @return boolean
28
     */
29
    public function exists() : bool
30
    {
31
        $theme = $this->dir()->theme($this->distributor, $this->name);
0 ignored issues
show
Bug Best Practice introduced by
The property distributor does not exist on Maestriam\Samurai\Foundation\ThemeSearch. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property name does not exist on Maestriam\Samurai\Foundation\ThemeSearch. Did you maybe forget to declare it?
Loading history...
Bug introduced by
The method dir() does not exist on Maestriam\Samurai\Foundation\ThemeSearch. ( Ignorable by Annotation )

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

31
        $theme = $this->/** @scrutinizer ignore-call */ dir()->theme($this->distributor, $this->name);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
33
        return (is_dir($theme)) ? true : false;
34
    }
35
36
    /**
37
     * Tenta encontrar um tema questão
38
     * Caso não encontre, constua-o
39
     *
40
     * @return Theme
41
     */
42
    public function findOrBuild() : Theme
43
    {
44
        if (! $this->exists()) {
45
            return $this->build();
0 ignored issues
show
Bug introduced by
The method build() does not exist on Maestriam\Samurai\Foundation\ThemeSearch. ( Ignorable by Annotation )

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

45
            return $this->/** @scrutinizer ignore-call */ build();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
        }
47
48
        return $this->get();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get() could return the type null which is incompatible with the type-hinted return Maestriam\Samurai\Foundation\Theme. Consider adding an additional type-check to rule them out.
Loading history...
49
    }
50
51
    /**
52
     * Retorna a instância de um tema
53
     * se caso o tema existir
54
     *
55
     * @return Theme|null
56
     */
57
    public function get() : ?Theme
58
    {
59
        if (! $this->exists()) {
60
            return null;
61
        }
62
63
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Maestriam\Samurai\Foundation\ThemeSearch which is incompatible with the type-hinted return Maestriam\Samurai\Foundation\Theme|null.
Loading history...
64
    }    
65
}
66