Link::getAnchor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Grido (https://github.com/o5/grido)
5
 *
6
 * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
7
 *
8
 * For the full copyright and license information, please view
9
 * the file LICENSE.md that was distributed with this source code.
10
 */
11
12
namespace Grido\Components\Columns;
13
14
/**
15
 * Link column.
16
 *
17
 * @package     Grido
18
 * @subpackage  Components\Columns
19
 * @author      Petr Bugyík
20
 */
21
class Link extends Text
22 1
{
23
    /**
24
     * @param mixed $value
25
     * @return \Nette\Utils\Html
26
     */
27
    protected function formatValue($value)
28
    {
29 1
        return $this->getAnchor($value);
30
    }
31
32
    /**
33
     * @param string $value
34 1
     * @return string
35
     */
36
    protected function formatHref($value)
37
    {
38 1
        if (!preg_match('~^\w+://~i', $value)) {
39 1
            $value = "http://" . $value;
40 1
        }
41
42 1
        return $value;
43
    }
44
45
    /**
46
     * @param string $value
47
     * @return string
48
     */
49
    protected function formatText($value)
50
    {
51 1
        return preg_replace('~^https?://~i', '', $value);
52
    }
53
54
    /**
55
     * @param mixed $value
56
     * @return \Nette\Utils\Html
57
     */
58
    protected function getAnchor($value)
59
    {
60 1
        $truncate = $this->truncate;
61 1
        $this->truncate = NULL;
62
63 1
        $value = parent::formatValue($value);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (formatValue() instead of getAnchor()). Are you sure this is correct? If so, you might want to change this to $this->formatValue().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
64 1
        $href = $this->formatHref($value);
65 1
        $text = $this->formatText($value);
66
67 1
        $anchor = \Nette\Utils\Html::el('a')
68 1
            ->setHref($href)
69 1
            ->setText($text)
70 1
            ->setTarget('_blank')
71 1
            ->setRel('noreferrer');
72
73 1
        if ($truncate) {
74 1
            $anchor->setText($truncate($text))
75 1
                ->setTitle($value);
76 1
        }
77
78 1
        return $anchor;
79
    }
80
}
81