1 | <?php |
||
12 | class save_blocks extends base_action |
||
13 | { |
||
14 | /** @var \blitze\sitemaker\model\blocks\mapper\blocks */ |
||
15 | protected $block_mapper; |
||
16 | |||
17 | /** @var \blitze\sitemaker\model\blocks\mapper\routes */ |
||
18 | protected $route_mapper; |
||
19 | |||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | 4 | public function execute($style_id) |
|
40 | |||
41 | /** |
||
42 | * @param \blitze\sitemaker\model\blocks\entity\route $entity |
||
43 | * @param array $blocks |
||
44 | */ |
||
45 | 4 | protected function save(\blitze\sitemaker\model\blocks\entity\route $entity, array $blocks) |
|
46 | { |
||
47 | // find all blocks for this route |
||
48 | 4 | $db_blocks = $this->get_blocks($entity); |
|
49 | |||
50 | 4 | $blocks_to_delete = array_filter(array_diff_key($db_blocks, $blocks)); |
|
51 | 4 | $blocks_to_update = array_filter(array_intersect_key($db_blocks, $blocks)); |
|
52 | |||
53 | 4 | $this->delete_blocks($blocks_to_delete); |
|
54 | 4 | $this->update_blocks($blocks_to_update, $blocks); |
|
55 | 4 | $this->update_route($blocks_to_update, $entity); |
|
56 | 4 | } |
|
57 | |||
58 | /** |
||
59 | * Get all blocks for route |
||
60 | * |
||
61 | * @param \blitze\sitemaker\model\blocks\entity\route $entity |
||
62 | * @return array |
||
63 | */ |
||
64 | 4 | protected function get_blocks(\blitze\sitemaker\model\blocks\entity\route $entity) |
|
77 | |||
78 | /** |
||
79 | * Delete specified blocks |
||
80 | * |
||
81 | * @param array $blocks_to_delete |
||
82 | */ |
||
83 | 4 | protected function delete_blocks(array $blocks_to_delete) |
|
90 | |||
91 | /** |
||
92 | * Update block position and weight |
||
93 | * |
||
94 | * @param array $blocks_to_update |
||
95 | * @param array $data |
||
96 | */ |
||
97 | 4 | protected function update_blocks(array $blocks_to_update, array $data) |
|
108 | |||
109 | /** |
||
110 | * Update route if it has blocks or route is customized, otherwise, delete the route |
||
111 | * |
||
112 | * @param array $blocks_to_update |
||
113 | * @param \blitze\sitemaker\model\blocks\entity\route $entity |
||
114 | */ |
||
115 | 4 | protected function update_route(array $blocks_to_update, \blitze\sitemaker\model\blocks\entity\route $entity) |
|
129 | } |
||
130 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.