Completed
Push — master ( 79bfd4...3da984 )
by ARCANEDEV
12s
created

ChangeFrequency   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 65
c 0
b 0
f 0
ccs 16
cts 16
cp 1
rs 10
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A keys() 0 12 1
A all() 0 6 1
A get() 0 4 1
A has() 0 4 1
1
<?php namespace Arcanedev\LaravelSitemap\Entities;
2
3
use Arcanedev\LaravelSitemap\Contracts\Entities\ChangeFrequency as ChangeFrequencyContract;
4
use Illuminate\Support\Collection;
5
6
/**
7
 * Class     ChangeFrequency
8
 *
9
 * @package  Arcanedev\LaravelSitemap\Entities
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class ChangeFrequency implements ChangeFrequencyContract
13
{
14
    /* -----------------------------------------------------------------
15
     |  Main Methods
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Get all the valid frequency keys.
21
     *
22
     * @return \Illuminate\Support\Collection
23
     */
24 10
    public static function keys()
25
    {
26 10
        return new Collection([
27 10
            static::ALWAYS,
28 10
            static::HOURLY,
29 10
            static::DAILY,
30 10
            static::WEEKLY,
31 10
            static::MONTHLY,
32 10
            static::YEARLY,
33 10
            static::NEVER,
34
        ]);
35
    }
36
37
    /**
38
     * Get all the valid frequency values.
39
     *
40
     * @param  string|null $locale
41
     *
42
     * @return \Illuminate\Support\Collection
43
     */
44
    public static function all($locale = null)
45
    {
46 6
        return static::keys()->mapWithKeys(function ($key) use ($locale) {
47 6
            return [$key => trans("sitemap::frequencies.$key", [], $locale)];
48 6
        });
49
    }
50
51
    /**
52
     * Get the translated frequency name.
53
     *
54
     * @param  string       $key
55
     * @param  string|null  $default
56
     * @param  string|null  $locale
57
     *
58
     * @return string|null
59
     */
60 2
    public static function get($key, $default = null, $locale = null)
61
    {
62 2
        return static::all($locale)->get($key, $default);
63
    }
64
65
    /**
66
     * Check if the given frequency exists.
67
     *
68
     * @param  string $key
69
     *
70
     * @return bool
71
     */
72 2
    public static function has($key)
73
    {
74 2
        return static::keys()->flip()->has($key);
75
    }
76
}
77