Passed
Push — master ( f85738...3d85c1 )
by Peter
04:52
created

UrlTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getShowUrl() 0 15 2
A getEditUrl() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Http\Controllers\Admin;
6
7
use AbterPhp\Framework\Constant\Session;
8
use Opulence\Routing\Urls\URLException;
9
use Opulence\Routing\Urls\UrlGenerator; // @phan-suppress-current-line
10
use Opulence\Sessions\ISession; // @phan-suppress-current-line
11
12
trait UrlTrait
13
{
14
    /**
15
     * @return string
16
     * @throws URLException
17
     */
18
    protected function getShowUrl(): string
19
    {
20
        /** @var ISession $session */
21
        $session = $this->session;
22
23
        if ($session->has(Session::LAST_GRID_URL)) {
24
            return (string)$session->get(Session::LAST_GRID_URL);
25
        }
26
27
        /** @var UrlGenerator $urlGenerator */
28
        $urlGenerator = $this->urlGenerator;
29
30
        $url = $urlGenerator->createFromName(strtolower(static::ENTITY_PLURAL));
0 ignored issues
show
Bug introduced by
The constant AbterPhp\Admin\Http\Cont...UrlTrait::ENTITY_PLURAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
32
        return $url;
33
    }
34
35
    /**
36
     * @param string $id
37
     *
38
     * @return string
39
     * @throws URLException
40
     */
41
    protected function getEditUrl(string $id): string
42
    {
43
        /** @var UrlGenerator $urlGenerator */
44
        $urlGenerator = $this->urlGenerator;
45
46
        $url = $urlGenerator->createFromName(sprintf(static::URL_EDIT, strtolower(static::ENTITY_PLURAL)), $id);
0 ignored issues
show
Bug introduced by
The constant AbterPhp\Admin\Http\Cont...dmin\UrlTrait::URL_EDIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant AbterPhp\Admin\Http\Cont...UrlTrait::ENTITY_PLURAL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
47
48
        return $url;
49
    }
50
}
51