Passed
Push — master ( 381e35...37729d )
by Chito
01:51
created

LampagerBehavior::findLampager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 5
crap 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
// @codeCoverageIgnoreStart
4
App::uses('ModelBehavior', 'Model');
5
App::uses('LampagerPaginator', 'Lampager.Model');
6
App::uses('LampagerArrayProcessor', 'Lampager.Model');
7
// @codeCoverageIgnoreEnd
8
9
class LampagerBehavior extends ModelBehavior
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
    /** @var string[] */
12
    public $mapMethods = [
13
        '/\b_findLampager\b/' => 'findLampager',
14
    ];
15
16
    /**
17
     * {@inheritdoc}
18
     */
19 32
    public function setup(Model $model, $config = [])
20
    {
21 32
        $model->findMethods['lampager'] = true;
22 32
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 32
    public function cleanup(Model $model)
28
    {
29 32
        unset($model->findMethods['lampager']);
30 32
    }
31
32
    /**
33
     * Hanldle the custom finder. Only called by Model::find().
34
     *
35
     * @param  Model  $model   Model.
36
     * @param  string $method  Method.
37
     * @param  string $state   Either "before" or "after"
38
     * @param  array  $query   Query.
39
     * @param  array  $results Results.
40
     * @return array
41
     */
42 32
    public function findLampager(Model $model, $method, $state, array $query = [], array $results = [])
0 ignored issues
show
Unused Code introduced by
The parameter $method is not used and could be removed.

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

Loading history...
43
    {
44 32
        return $this->{__FUNCTION__ . ucfirst($state)}($model, $query, $results);
45
    }
46
47 32
    protected function findLampagerBefore(Model $model, array $query = [], array $results = [])
0 ignored issues
show
Unused Code introduced by
The parameter $results is not used and could be removed.

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

Loading history...
48
    {
49 32
        return LampagerPaginator::create($model, $query)->transformer->build(isset($query['cursor']) ? $query['cursor'] : []);
50
    }
51
52 32
    protected function findLampagerAfter(Model $model, array $query = [], array $results = [])
53
    {
54 32
        return LampagerArrayProcessor::create($model)->process($query['config'], $results);
55
    }
56
57
    /**
58
     * Paginate the Model. Only called by PaginatorComponent::paginate().
59
     *
60
     * @param Model $model
61
     * @param array $conditions
62
     * @param array $fields
63
     * @param array $order
64
     * @param int   $limit
65
     * @param int   $page
66
     * @param int   $recursive
67
     * @param array $extra
68
     */
69 16
    public function paginate(Model $model, $conditions, $fields, $order, $limit, $page = 1, $recursive = null, array $extra = [])
70
    {
71
        /**
72
         * Extract extra parameters which may include
73
         *
74
         * @var bool  $forward
75
         * @var bool  $backward
76
         * @var bool  $exclusive
77
         * @var bool  $inclusive
78
         * @var bool  $seekable
79
         * @var bool  $unseekable
80
         * @var array $cursor
81
         */
82 16
        extract($extra, EXTR_SKIP);
83
84 16
        return $model->find('lampager', compact(
85 16
            'conditions',
86 16
            'fields',
87 16
            'order',
88 16
            'limit',
89 16
            'page',
90 16
            'recursive',
91 16
            'forward',
92 16
            'backward',
93 16
            'exclusive',
94 16
            'inclusive',
95 16
            'seekable',
96 16
            'unseekable',
97 16
            'cursor'
98
        ));
99
    }
100
}
101