Intl   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 58
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
getLocale() 0 1 ?
setLocale() 0 1 ?
getFallbackLocale() 0 1 ?
setFallbackLocale() 0 1 ?
A usingLocale() 0 15 2
1
<?php
2
3
namespace Propaganistas\LaravelIntl\Contracts;
4
5
use Illuminate\Support\Traits\Macroable;
6
7
abstract class Intl
8
{
9
    use Macroable;
10
    
11
    /**
12
     * Get the current locale.
13
     *
14
     * @return string
15
     */
16
    abstract public function getLocale();
17
18
    /**
19
     * Set the current locale.
20
     *
21
     * @param $locale
22
     * @return $this
23
     */
24
    abstract public function setLocale($locale);
25
26
    /**
27
     * Get the fallback locale.
28
     *
29
     * @return string
30
     */
31
    abstract public function getFallbackLocale();
32
33
    /**
34
     * Set the fallback locale.
35
     *
36
     * @param $locale
37
     * @return $this
38
     */
39
    abstract public function setFallbackLocale($locale);
40
41
    /**
42
     * Run the given callable while using another locale.
43
     *
44
     * @param string $locale
45
     * @param callable $callback
46
     * @param string|null $fallbackLocale
47
     * @return mixed
48
     */
49 12
    public function usingLocale($locale, callable $callback, $fallbackLocale = null)
50
    {
51 12
        $originalLocale = $this->getLocale();
52 12
        $originalFallbackLocale = $this->getFallbackLocale();
53
54 12
        $this->setLocale($locale);
55 12
        $this->setFallbackLocale($fallbackLocale ?: $originalFallbackLocale);
56
57 12
        $result = $callback($this);
58
59 12
        $this->setFallbackLocale($originalFallbackLocale);
60 12
        $this->setLocale($originalLocale);
61
62 12
        return $result;
63
    }
64
}
65