Passed
Pull Request — master (#16)
by Eric
12:51
created

Counter::read()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
nc 4
nop 1
dl 0
loc 30
c 1
b 0
f 0
cc 4
rs 9.7998
ccs 11
cts 11
cp 1
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Esi\SimpleCounter.
7
 *
8
 * (c) Eric Sizemore <https://github.com/ericsizemore>
9
 *
10
 * This source file is subject to the MIT license. For the full copyright and
11
 * license information, please view the LICENSE file that was distributed with
12
 * this source code.
13
 */
14
15
namespace Esi\SimpleCounter;
16
17
use Esi\SimpleCounter\Interface\StorageInterface;
18
19
/**
20
 * Essentially a wrapper for a given Storage implementation.
21
 *
22
 * @see Tests\CounterTest
23
 */
24
readonly class Counter
25
{
26
    /**
27
     * Current Simple Counter package version.
28
     */
29
    public const VERSION = '6.0.0';
30
31
    /**
32
     * $storage should be one of the available Storage implementations that has already
33
     * been instantiated with their relevant Configuration.
34
     */
35 4
    public function __construct(private StorageInterface $storage) {}
36
37
    /**
38
     * Updates count and formats for display, for the given Storage implementation.
39
     */
40 3
    public function display(): string
41
    {
42 3
        return $this->storage->display();
43
    }
44
45
    /**
46
     * Useful for retrieving the current count without triggering an update.
47
     */
48 1
    public function fetchCurrentCount(): int
49
    {
50 1
        return $this->storage->fetchCurrentCount();
51
    }
52
53
    /**
54
     * Returns ip data, if any exists.
55
     *
56
     * @return list<string>
1 ignored issue
show
Bug introduced by
The type Esi\SimpleCounter\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
57
     */
58 1
    public function fetchCurrentIpList(): array
59
    {
60 1
        return $this->storage->fetchCurrentIpList();
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->storage->fetchCurrentIpList() returns the type array which is incompatible with the documented return type Esi\SimpleCounter\list.
Loading history...
61
    }
62
63
    /**
64
     * Returns the given option, if it exists.
65
     */
66 1
    public function getOption(string $option): null|bool|string
67
    {
68 1
        return $this->storage->getOption($option);
69
    }
70
}
71