ChangeFrequency::all()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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