GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Indexable::addIndex()   A
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.0777
c 0
b 0
f 0
cc 6
nc 4
nop 2
1
<?php
2
3
namespace TheIconic\Tracking\GoogleAnalytics\Traits;
4
5
use TheIconic\Tracking\GoogleAnalytics\Exception\InvalidIndexException;
6
use TheIconic\Tracking\GoogleAnalytics\Exception\InvalidNameException;
7
8
/**
9
 * Class Indexable
10
 *
11
 * Contains logic for indexing a parameter string with a valid placeholder.
12
 *
13
 * @package TheIconic\Tracking\GoogleAnalytics\Traits
14
 */
15
trait Indexable
16
{
17
    /**
18
     * Placeholder for the index.
19
     */
20
    private $indexPlaceholder = ':i:';
21
22
    /**
23
     * Minimum value index can take in GA.
24
     *
25
     * @return int
26
     */
27
    protected function minIndex()
28
    {
29
        return 1;
30
    }
31
32
    /**
33
     * Maximum value index can take in GA.
34
     *
35
     * @return int
36
     */
37
    protected function maxIndex()
38
    {
39
        return 200;
40
    }
41
42
    /**
43
     * Replaces a placeholder for the index passed.
44
     *
45
     * @param string $string
46
     * @param int $index
47
     * @return string
48
     * @throws \TheIconic\Tracking\GoogleAnalytics\Exception\InvalidIndexException
49
     * @throws \TheIconic\Tracking\GoogleAnalytics\Exception\InvalidNameException
50
     */
51
    protected function addIndex($string, $index)
52
    {
53
        if (empty($string)) {
54
            throw new InvalidNameException('Name attribute not defined for class ' . get_class($this));
55
        }
56
57
        if (strpos($string, $this->indexPlaceholder) !== false) {
58
            if (!is_numeric($index) || $index < $this->minIndex() || $index > $this->maxIndex()) {
59
                throw new InvalidIndexException(
60
                    'When setting parameter ' . get_class($this)
61
                    . ' a numeric index between 1 - 200 must be passed for the second argument'
62
                );
63
            }
64
        }
65
66
        return str_replace($this->indexPlaceholder, $index, $string);
67
    }
68
}
69