getCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
nop 0
1
<?php
2
/**
3
 * integer_net Magento Module
4
 *
5
 * @category   IntegerNet
6
 * @package    IntegerNet_Anonymizer
7
 * @copyright  Copyright (c) 2015 integer_net GmbH (http://www.integer-net.de/)
8
 * @author     Fabian Schmengler <[email protected]>
9
 */
10
class IntegerNet_Anonymizer_Model_Bridge_Iterator implements \IntegerNet\Anonymizer\Implementor\CollectionIterator
11
{
12
    /**
13
     * @var Mage_Eav_Model_Entity_Collection_Abstract|Mage_Core_Model_Resource_Db_Collection_Abstract
14
     */
15
    protected $_collection;
16
    /**
17
     * @var Mage_Core_Model_Resource_Iterator
18
     */
19
    protected $_iterator;
20
    /**
21
     * @var string[]
22
     */
23
    protected $_data;
24
    /**
25
     * @var int Iteration counter
26
     */
27
    protected $_iteration;
28
    /**
29
     * @var int Iteration counter offset for chunking
30
     */
31
    protected $_iterationOffset = 0;
32
33
    public function __construct(Varien_Data_Collection_Db $collection)
34
    {
35
        $this->_collection = $collection;
0 ignored issues
show
Documentation Bug introduced by
It seems like $collection of type object<Varien_Data_Collection_Db> is incompatible with the declared type object<Mage_Eav_Model_En...Db_Collection_Abstract> of property $_collection.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
36
        $this->_iterator = Mage::getResourceModel('core/iterator');
37
    }
38
39
    /**
40
     * @return Mage_Core_Model_Resource_Db_Collection_Abstract|Mage_Eav_Model_Entity_Collection_Abstract
41
     */
42
    public function getCollection()
43
    {
44
        return $this->_collection;
45
    }
46
47
    /**
48
     * @param callable $callable
49
     * @return mixed
50
     */
51
    function walk(/*callable*/ $callable) // PHP 5.3
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...
52
    {
53
        $self = $this; // PHP 5.3
54
        $this->_iterator->walk($this->_collection->getSelect(), array(
55
            function($args) use ($callable, $self) {
56
                $self->_setIteration($args['idx']);
57
                $self->_setRawData($args['row']);
58
                $callable($self);
59
            }
60
        ));
61
        $this->_afterWalk();
62
    }
63
64
    public function _setRawData($data)
65
    {
66
        $this->_data = $data;
67
    }
68
    public function _setIteration($iteration)
69
    {
70
        $this->_iteration = $iteration;
71
    }
72
    public function setIterationOffset($offset)
73
    {
74
        $this->_iterationOffset = $offset;
75
    }
76
77
    /**
78
     * Returns raw data from database
79
     *
80
     * @return mixed
81
     */
82
    function getRawData()
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...
83
    {
84
        return $this->_data;
85
    }
86
87
    /**
88
     * Returns number of iteration
89
     *
90
     * @return int
91
     */
92
    function getIteration()
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...
93
    {
94
        return $this->_iterationOffset + $this->_iteration;
95
    }
96
97
    /**
98
     * Returns total size of collection
99
     *
100
     * @return mixed
101
     */
102
    function getSize()
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...
103
    {
104
        return $this->_collection->getSize();
105
    }
106
107
    /**
108
     * Additional processing at the end:
109
     *  - update grid tables
110
     *
111
     * @return void
112
     */
113
    protected function _afterWalk()
114
    {
115
        $entityResource = $this->_collection->getResource();
116
        if ($entityResource instanceof Mage_Sales_Model_Resource_Order_Abstract) {
0 ignored issues
show
Bug introduced by
The class Mage_Sales_Model_Resource_Order_Abstract does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
117
            $entityResource->updateGridRecords($this->_collection->getAllIds());
118
        }
119
    }
120
121
}