Passed
Push — master ( bf2aee...a6dc35 )
by Thierry
02:22
created

UtilTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerUtils() 0 40 1
A getTemplateEngine() 0 3 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Di\Traits;
4
5
use Jaxon\Utils\Config\ConfigReader;
0 ignored issues
show
Bug introduced by
The type Jaxon\Utils\Config\ConfigReader 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...
6
use Jaxon\Utils\File\FileMinifier;
0 ignored issues
show
Bug introduced by
The type Jaxon\Utils\File\FileMinifier 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...
7
use Jaxon\Utils\Http\UriDetector;
8
use Jaxon\Utils\Template\TemplateEngine;
0 ignored issues
show
Bug introduced by
The type Jaxon\Utils\Template\TemplateEngine 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...
9
use Jaxon\Utils\Translation\Translator;
10
11
use function rtrim;
12
use function trim;
13
14
trait UtilTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait UtilTrait
Loading history...
15
{
16
    /**
17
     * Register the values into the container
18
     *
19
     * @return void
20
     */
21
    private function registerUtils()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
22
    {
23
        // Translator
24
        $this->set(Translator::class, function($c) {
0 ignored issues
show
Bug introduced by
It seems like set() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
        $this->/** @scrutinizer ignore-call */ 
25
               set(Translator::class, function($c) {
Loading history...
25
            $xTranslator = new Translator();
0 ignored issues
show
Bug introduced by
The call to Jaxon\Utils\Translation\Translator::__construct() has too few arguments starting with sDefaultLocale. ( Ignorable by Annotation )

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

25
            $xTranslator = /** @scrutinizer ignore-call */ new Translator();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
26
            $sResourceDir = rtrim(trim($c->g('jaxon.core.dir.translation')), '/\\');
27
            // Load the Jaxon package translations
28
            $xTranslator->loadTranslations($sResourceDir . '/en/errors.php', 'en');
29
            $xTranslator->loadTranslations($sResourceDir . '/fr/errors.php', 'fr');
30
            $xTranslator->loadTranslations($sResourceDir . '/es/errors.php', 'es');
31
            // Load the config translations
32
            $xTranslator->loadTranslations($sResourceDir . '/en/config.php', 'en');
33
            $xTranslator->loadTranslations($sResourceDir . '/fr/config.php', 'fr');
34
            $xTranslator->loadTranslations($sResourceDir . '/es/config.php', 'es');
35
            // Load the upload translations
36
            $xTranslator->loadTranslations($sResourceDir . '/en/upload.php', 'en');
37
            $xTranslator->loadTranslations($sResourceDir . '/fr/upload.php', 'fr');
38
            $xTranslator->loadTranslations($sResourceDir . '/es/upload.php', 'es');
39
            return $xTranslator;
40
        });
41
        // Config reader
42
        $this->set(ConfigReader::class, function() {
43
            return new ConfigReader();
44
        });
45
        // Template engine
46
        $this->set(TemplateEngine::class, function($c) {
47
            $xTemplateEngine = new TemplateEngine();
48
            $sTemplateDir = rtrim(trim($c->g('jaxon.core.dir.template')), '/\\');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
49
            $sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination';
50
            $xTemplateEngine->addNamespace('jaxon', $sTemplateDir, '.php');
51
            $xTemplateEngine->addNamespace('pagination', $sPaginationDir, '.php');
52
            return $xTemplateEngine;
53
        });
54
        // File minifier
55
        $this->set(FileMinifier::class, function() {
56
            return new FileMinifier();
57
        });
58
        // URI detector
59
        $this->set(UriDetector::class, function() {
60
            return new UriDetector();
61
        });
62
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
63
64
    /**
65
     * Get the template engine
66
     *
67
     * @return TemplateEngine
68
     */
69
    public function getTemplateEngine(): TemplateEngine
70
    {
71
        return $this->g(TemplateEngine::class);
0 ignored issues
show
Bug introduced by
It seems like g() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

71
        return $this->/** @scrutinizer ignore-call */ g(TemplateEngine::class);
Loading history...
72
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
73
}
74