ServiceRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getServiceByUrl() 0 11 2
A isUrlValid() 0 6 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: leo108
5
 * Date: 16/9/17
6
 * Time: 20:13
7
 */
8
9
namespace Leo108\CAS\Repositories;
10
11
use Leo108\CAS\Models\Service;
12
use Leo108\CAS\Models\ServiceHost;
13
14
class ServiceRepository
15
{
16
    /**
17
     * @var Service
18
     */
19
    protected $service;
20
21
    /**
22
     * @var ServiceHost;
23
     */
24
    protected $serviceHost;
25
26
    /**
27
     * ServiceRepository constructor.
28
     * @param Service     $service
29
     * @param ServiceHost $serviceHost
30
     */
31 27
    public function __construct(Service $service, ServiceHost $serviceHost)
32
    {
33 27
        $this->service     = $service;
34 27
        $this->serviceHost = $serviceHost;
35 27
    }
36
37
    /**
38
     * @param $url
39
     * @return Service|null
40
     */
41 1
    public function getServiceByUrl($url)
42
    {
43 1
        $host = parse_url($url, PHP_URL_HOST);
44
45 1
        $record = $this->serviceHost->where('host', $host)->first();
46 1
        if (!$record) {
47 1
            return null;
48
        }
49
50 1
        return $record->service;
51
    }
52
53
    /**
54
     * @param $url
55
     * @return bool
56
     */
57 1
    public function isUrlValid($url)
58
    {
59 1
        $service = $this->getServiceByUrl($url);
60
61 1
        return $service !== null && $service->enabled;
62
    }
63
}
64