Passed
Branch master (b3bcb6)
by Alexander
02:46
created

DefaultHandler::getTranslation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 *
5
 * Base Handler to extend from
6
 *
7
 * @package  Hokan22\LaravelTranslator\Handler
8
 * @author   Alexander Viertel <[email protected]>
9
 * @license  http://opensource.org/licenses/MIT MIT
10
 */
11
namespace Hokan22\LaravelTranslator\Handler;
12
13
/**
14
 * Custom Exception to distinguish if the Translation Identifier or
15
 * the Translation was not found for the given locale
16
 *
17
 * Class TranslationNotFoundException
18
 */
19
class TranslationNotFoundException extends \Exception {}
20
21
/**
22
 * Custom Exception to distinguish if the Translation Identifier was not found in Cache but could be in DB
23
 *
24
 * Class TranslationNotInCacheException
25
 */
26
class TranslationNotInCacheException extends TranslationNotFoundException {}
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
27
28
/**
29
 * Custom Exception thrown when a cache file could not be found
30
 *
31
 * Class TranslationCacheNotFound
32
 */
33
class TranslationCacheNotFound extends \Exception {}
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
34
35
/**
36
 * Interface HandlerInterface
37
 */
38
class DefaultHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
39
{
40
    /**
41
     * @var string          $locale         The locale to translate to
42
     * @var array|array[]   $translations   Array with the identifiers as keys and the Texts object as value
43
     */
44
    protected $locale, $translations;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
45
46
    /**
47
     * HandlerInterface constructor.
48
     *
49
     * @param $locale
50
     */
51
    function __construct($locale){
52
         $this->locale = $locale;
53
    }
54
55
    /**
56
     * Should return the locale currently set in the handler
57
     *
58
     * @return string
59
     */
60
    function getLocale(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
61
        return $this->locale;
62
    }
63
64
    /**
65
     * Get the translation of a given identifier
66
     *
67
     * @param string $identifier
68
     * @param string $group
69
     * @return string
70
     */
71
    function getTranslation($identifier, $group){
0 ignored issues
show
Unused Code introduced by
The parameter $group is not used and could be removed. ( Ignorable by Annotation )

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

71
    function getTranslation($identifier, /** @scrutinizer ignore-unused */ $group){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
72
        return $identifier;
73
    }
74
75
    /**
76
     * Refresh the internal Cache
77
     *
78
     * @return bool
79
     */
80
    function refreshCache(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
81
        return true;
82
    }
83
84
    /**
85
     * Get all translations of a given group
86
     *
87
     * @param string $group
88
     * @return array
89
     */
90
    function getAllTranslations($group){
0 ignored issues
show
Unused Code introduced by
The parameter $group is not used and could be removed. ( Ignorable by Annotation )

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

90
    function getAllTranslations(/** @scrutinizer ignore-unused */ $group){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
91
        return [];
92
    }
93
94
}