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.
Passed
Push — master ( 277531...da2303 )
by Toby
06:21 queued 02:58
created

UrlSigner::group()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Linkeys\UrlSigner;
4
5
use \DateTime;
6
use Linkeys\UrlSigner\Contracts\UrlSigner as UrlSignerContract;
7
use Linkeys\UrlSigner\Contracts\Models\Link as LinkContract;
8
use Linkeys\UrlSigner\Models\Link;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Linkeys\UrlSigner\Link. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use Linkeys\UrlSigner\Support\GroupRepository\GroupRepository;
10
use Linkeys\UrlSigner\Support\LinkRepository\LinkRepository;
11
use Linkeys\UrlSigner\Support\UrlManipulator\UrlManipulator;
12
13
class UrlSigner implements UrlSignerContract
14
{
15
    protected $linkRepository;
16
17
    protected $urlParser;
18
19
    protected $queryParameter = 'uuid';
20
21
    private $group;
22
    /**
23
     * @var GroupRepository
24
     */
25
    private $groupRepository;
26
27 5
    public function __construct(LinkRepository $linkRepository, GroupRepository $groupRepository, UrlManipulator $urlParser)
28
    {
29 5
        $this->linkRepository = $linkRepository;
30 5
        $this->urlParser = $urlParser;
31 5
        $this->groupRepository = $groupRepository;
32 5
    }
33
34
    /**
35
     * Create a new link
36
     *
37
     * @param string $url
38
     * @param array|null $data
39
     * @param DateTime|int|string|null $expiry
40
     * @param null $clickLimit
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $clickLimit is correct as it would always require null to be passed?
Loading history...
41
     * @return Link
42
     * @throws \Exception
43
     */
44 4
    public function generate(string $url, $data = [], $expiry = null, $clickLimit = null) : LinkContract
45
    {
46 4
        $link = $this->linkRepository->create([
47 4
            'url' => $url,
48 4
            'data' => $data,
49 4
            'click_limit' => $clickLimit,
50 4
            'expiry' => $expiry
51
        ]);
52
53 4
        if($this->group !== null) {
54 2
            $this->groupRepository->pushLink($this->group, $link);
55
        }
56
57 4
        return $link;
58
    }
59
60 3
    public function group(callable $callback, $expiry = null, $clickLimit = null)
61
    {
62 3
        $group = $this->groupRepository->create([
63 3
            'expiry' => $expiry,
64 3
            'clickLimit' => $clickLimit
65
        ]);
66
67 3
        $this->group = $group;
68 3
        $callback($this);
69 3
        $this->group = null;
70
71 3
        return $group;
72
    }
73
74
}