1 | <?php |
||
20 | class PageTotalsRow implements PartInterface, ViewComponentInterface |
||
21 | { |
||
22 | use PartTrait { |
||
23 | PartTrait::attachToCompound as attachToCompoundInternal; |
||
24 | } |
||
25 | use ChildNodeTrait; |
||
26 | use ViewTrait; |
||
27 | |||
28 | const ID = 'page_totals_row'; |
||
29 | |||
30 | const OPERATION_SUM = 'sum'; |
||
31 | const OPERATION_AVG = 'avg'; |
||
32 | const OPERATION_COUNT = 'count'; |
||
33 | const OPERATION_IGNORE = 'ignore'; |
||
34 | |||
35 | protected $valuePrefixes = [ |
||
36 | self::OPERATION_SUM => 'Σ', |
||
37 | self::OPERATION_AVG => 'Avg.', |
||
38 | self::OPERATION_COUNT => 'Count:' |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Keys are column id's and values are operations (see PageTotalsRow::OPERATION_* constants). |
||
43 | * |
||
44 | * @var string[]|array |
||
45 | */ |
||
46 | protected $operations; |
||
47 | |||
48 | protected $totalData; |
||
49 | |||
50 | protected $cellObserver; |
||
51 | |||
52 | protected $rowsProcessed = 0; |
||
53 | |||
54 | private $isTotalsCalculationFinished = false; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | private $defaultOperation; |
||
60 | |||
61 | /** |
||
62 | * PageTotalsRow constructor. |
||
63 | * |
||
64 | * Operations passed to first argument ($operations) may contain values |
||
65 | * of PageTotalsRow::OPERATIN_* constants or Closure or null. Keys must be equal to target column id's |
||
66 | * If $operations has no value for column, default operation will be used for that column. |
||
67 | * |
||
68 | * Closure passed to operations can accept |
||
69 | * accumulated value in first argument and current row value in second argument. |
||
70 | * |
||
71 | * @param array|string[] $operations (optional) keys are column id's and values are operations |
||
72 | * (see PageTotalsRow::OPERATION_* constants) or closures. |
||
73 | * @param string|null $defaultOperation operation that will be used for column |
||
74 | * if operation isn't specified for this column in first argument. |
||
75 | */ |
||
76 | public function __construct(array $operations = [], $defaultOperation = null) |
||
86 | |||
87 | /** |
||
88 | * @param Compound|Grid $root |
||
89 | * @param bool $prepend |
||
90 | */ |
||
91 | public function attachToCompound(Compound $root, $prepend = false) |
||
96 | |||
97 | /** |
||
98 | * Returns string prefixes for data printed in totals row for different operations. |
||
99 | * |
||
100 | * Keys are operations and values are prefixes. |
||
101 | * |
||
102 | * @return string[] |
||
103 | */ |
||
104 | public function getValuePrefixes() |
||
108 | |||
109 | /** |
||
110 | * Sets string prefixes for data printed in totals row for different operations. |
||
111 | * |
||
112 | * @param string[] $valuePrefixes keys are operations and values are prefixes. |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function setValuePrefixes(array $valuePrefixes) |
||
120 | |||
121 | /** |
||
122 | * Renders tag and returns output. |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function render() |
||
166 | |||
167 | protected function pushData($field, $value) |
||
215 | |||
216 | /** |
||
217 | * @param string $columnName |
||
218 | * @return string|Closure|null |
||
219 | */ |
||
220 | protected function getOperation($columnName) |
||
226 | |||
227 | protected function processCurrentRow() |
||
239 | |||
240 | protected function replaceGridDataInjector(Grid $grid) |
||
248 | } |
||
249 |
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.