| Conditions | 7 |
| Paths | 20 |
| Total Lines | 30 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 30 | public function setCanonical() |
||
| 31 | { |
||
| 32 | $request = Yii::$app->request; |
||
| 33 | $setCanonical = false; |
||
| 34 | $queryParams = !empty($request->queryParams) ? $request->queryParams : []; |
||
| 35 | $this->_canonical = $request->absoluteUrl; |
||
| 36 | |||
| 37 | foreach ($this->labels as $label) { |
||
| 38 | foreach ($queryParams as $key => $value) { |
||
| 39 | if ($key == $label) { |
||
| 40 | if (false == empty($value)) { |
||
|
|
|||
| 41 | $rm = $key .'='. $value; |
||
| 42 | } else { |
||
| 43 | $rm = $key; |
||
| 44 | } |
||
| 45 | $this->_canonical = str_replace(['?'.$rm.'&', '?'.$rm, '&'.$rm], ['?','',''], $this->_canonical); |
||
| 46 | $setCanonical = true; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($setCanonical) { |
||
| 52 | $this->owner->view->registerLinkTag( |
||
| 53 | [ |
||
| 54 | 'rel' => 'canonical', |
||
| 55 | 'href' => $this->_canonical |
||
| 56 | ] |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.