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   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A minIndex() 0 4 1
A maxIndex() 0 4 1
A addIndex() 0 17 6
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