EloquentRedirector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 46
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRedirectedUrls() 0 9 1
A getCachedRedirects() 0 6 1
A getRedirectModel() 0 6 1
1
<?php namespace Arcanedev\LaravelSeo\Redirectors;
2
3
use Arcanedev\LaravelSeo\Contracts\Redirector;
4
use Arcanedev\LaravelSeo\Models\Redirect;
5
6
/**
7
 * Class     EloquentRedirector
8
 *
9
 * @package  Arcanedev\LaravelSeo\Redirectors
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class EloquentRedirector extends AbstractRedirector implements Redirector
13
{
14
    /* -----------------------------------------------------------------
15
     |  Main Methods
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Get the redirected URLs.
21
     *
22
     * @return array
23
     */
24 2
    public function getRedirectedUrls()
25
    {
26 2
        return $this->getCachedRedirects()
27 2
            ->keyBy('old_url')
28 2
            ->transform(function (Redirect $item) {
29 2
                return [$item->new_url, $item->status];
30 2
            })
31 2
            ->toArray();
32
    }
33
34
    /**
35
     * Get the cached redirection urls.
36
     *
37
     * @return \Illuminate\Database\Eloquent\Collection
38
     */
39
    protected function getCachedRedirects()
40
    {
41 2
        return cache()->remember($this->getOption('cache.key'), $this->getOption('cache.duration'), function () {
42 2
            return $this->getRedirectModel()->get();
43 2
        });
44
    }
45
46
    /**
47
     * Get the redirect model.
48
     *
49
     * @return \Arcanedev\LaravelSeo\Models\Redirect
50
     */
51 2
    private function getRedirectModel()
52
    {
53 2
        return app(
54 2
            $this->getOption('model', \Arcanedev\LaravelSeo\Models\Redirect::class)
55
        );
56
    }
57
}
58