Passed
Push — v5.x ( 57c2ac...73bdb8 )
by Thierry
16:58 queued 05:55
created

ViewTrait::getPaginator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\App\Config\ConfigManager;
6
use Jaxon\App\Dialog\Library\AlertLibrary;
7
use Jaxon\App\Dialog\Library\DialogLibraryHelper;
8
use Jaxon\App\Dialog\Library\DialogLibraryManager;
9
use Jaxon\App\Dialog\LibraryInterface;
10
use Jaxon\App\Dialog\MessageInterface;
11
use Jaxon\App\Dialog\ModalInterface;
12
use Jaxon\App\Dialog\QuestionInterface;
13
use Jaxon\App\I18n\Translator;
14
use Jaxon\App\View\TemplateView;
15
use Jaxon\App\View\ViewRenderer;
16
use Jaxon\Di\Container;
17
use Jaxon\Utils\Template\TemplateEngine;
18
19
use function call_user_func;
20
use function rtrim;
21
use function trim;
22
23
trait ViewTrait
0 ignored issues
show
Coding Style introduced by
Missing doc comment for trait ViewTrait
Loading history...
24
{
25
    /**
26
     * Register the values into the container
27
     *
28
     * @return void
29
     */
30
    private function registerViews()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
31
    {
32
        // Jaxon template view
33
        $this->set(TemplateView::class, function($di) {
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

33
        $this->/** @scrutinizer ignore-call */ 
34
               set(TemplateView::class, function($di) {
Loading history...
34
            return new TemplateView($di->g(TemplateEngine::class));
35
        });
36
        // View Renderer
37
        $this->set(ViewRenderer::class, function($di) {
38
            $xViewRenderer = new ViewRenderer($di->g(Container::class));
39
            // Add the default view renderer
40
            $xViewRenderer->addRenderer('jaxon', function($di) {
41
                return $di->g(TemplateView::class);
42
            });
43
            $sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 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...
44
            $sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination';
45
            // By default, render pagination templates with Jaxon.
46
            $xViewRenderer->addNamespace('jaxon', $sTemplateDir, '.php', 'jaxon');
47
            $xViewRenderer->addNamespace('pagination', $sPaginationDir, '.php', 'jaxon');
48
            return $xViewRenderer;
49
        });
50
51
        // Dialog library manager
52
        $this->set(DialogLibraryManager::class, function($di) {
53
            return new DialogLibraryManager($di->g(Container::class), $di->g(ConfigManager::class), $di->g(Translator::class));
54
        });
55
        $this->val(AlertLibrary::class, new AlertLibrary());
0 ignored issues
show
Bug introduced by
It seems like val() 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

55
        $this->/** @scrutinizer ignore-call */ 
56
               val(AlertLibrary::class, new AlertLibrary());
Loading history...
56
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
57
58
    /**
59
     * Register a javascript dialog library adapter.
60
     *
61
     * @param string $sClass
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
62
     * @param string $sLibraryName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
63
     *
64
     * @return void
65
     */
66
    public function registerDialogLibrary(string $sClass, string $sLibraryName)
67
    {
68
        $this->set($sClass, function($di) use($sClass) {
69
            // Set the protected attributes of the library
70
            $cSetter = function() use($di) {
71
                $this->xHelper = new DialogLibraryHelper($this, $di->g(ConfigManager::class), $di->g(TemplateEngine::class));
0 ignored issues
show
Bug introduced by
$this of type Jaxon\Di\Traits\ViewTrait is incompatible with the type Jaxon\App\Dialog\LibraryInterface expected by parameter $xDialogLibrary of Jaxon\App\Dialog\Library...ryHelper::__construct(). ( Ignorable by Annotation )

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

71
                $this->xHelper = new DialogLibraryHelper(/** @scrutinizer ignore-type */ $this, $di->g(ConfigManager::class), $di->g(TemplateEngine::class));
Loading history...
Bug Best Practice introduced by
The property xHelper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
72
            };
73
            // Can now access protected attributes
74
            $xLibrary = $di->make($sClass);
75
            call_user_func($cSetter->bindTo($xLibrary, $xLibrary));
76
            return $xLibrary;
77
        });
78
        // Set the alias, so the libraries can be found by their names.
79
        $this->alias("dialog_library_$sLibraryName", $sClass);
0 ignored issues
show
Bug introduced by
It seems like alias() 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

79
        $this->/** @scrutinizer ignore-call */ 
80
               alias("dialog_library_$sLibraryName", $sClass);
Loading history...
80
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
81
82
    /**
83
     * Get a dialog library
84
     *
85
     * @param string $sLibraryName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
86
     *
87
     * @return LibraryInterface
88
     */
89
    public function getDialogLibrary(string $sLibraryName): LibraryInterface
90
    {
91
        return $this->g("dialog_library_$sLibraryName");
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

91
        return $this->/** @scrutinizer ignore-call */ g("dialog_library_$sLibraryName");
Loading history...
92
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
93
94
    /**
95
     * Get the QuestionInterface library
96
     *
97
     * @param string $sLibraryName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
98
     *
99
     * @return QuestionInterface
100
     */
101
    public function getQuestionLibrary(string $sLibraryName): QuestionInterface
102
    {
103
        $sKey = "dialog_library_$sLibraryName";
104
        return $this->h($sKey) ? $this->g($sKey) : $this->g(AlertLibrary::class);
0 ignored issues
show
Bug introduced by
It seems like h() 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

104
        return $this->/** @scrutinizer ignore-call */ h($sKey) ? $this->g($sKey) : $this->g(AlertLibrary::class);
Loading history...
105
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
106
107
    /**
108
     * Get the MessageInterface library
109
     *
110
     * @param string $sLibraryName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
111
     *
112
     * @return MessageInterface
113
     */
114
    public function getMessageLibrary(string $sLibraryName): MessageInterface
115
    {
116
        $sKey = "dialog_library_$sLibraryName";
117
        return $this->h($sKey) ? $this->g($sKey) : $this->g(AlertLibrary::class);
118
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
119
120
    /**
121
     * Get the ModalInterface library
122
     *
123
     * @param string $sLibraryName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
124
     *
125
     * @return ModalInterface|null
126
     */
127
    public function getModalLibrary(string $sLibraryName): ?ModalInterface
128
    {
129
        $sKey = "dialog_library_$sLibraryName";
130
        return $this->h($sKey) ? $this->g($sKey) : null;
131
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
132
133
    /**
134
     * Get the dialog library manager
135
     *
136
     * @return DialogLibraryManager
137
     */
138
    public function getDialogLibraryManager(): DialogLibraryManager
139
    {
140
        return $this->g(DialogLibraryManager::class);
141
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
142
143
    /**
144
     * Get the view renderer
145
     *
146
     * @return ViewRenderer
147
     */
148
    public function getViewRenderer(): ViewRenderer
149
    {
150
        return $this->g(ViewRenderer::class);
151
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
152
}
153