ClientFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 48
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A instance() 0 6 1
1
<?php
2
3
namespace NotificationChannels\Apn;
4
5
use Illuminate\Contracts\Cache\Repository;
6
use Illuminate\Contracts\Container\Container;
7
use Illuminate\Support\Carbon;
8
use Pushok\Client;
9
10
class ClientFactory
11
{
12
    /**
13
     * The number of minutes to cache the client.
14
     *
15
     * @var int
16
     */
17
    const CACHE_MINUTES = 20;
18
19
    /**
20
     * The app instance.
21
     *
22
     * @var \Illuminate\Contracts\Container\Container
23
     */
24
    protected $app;
25
26
    /**
27
     * The cache repository instance.
28
     *
29
     * @var \Illuminate\Contracts\Cache\Repository
30
     */
31
    protected $cache;
32
33
    /**
34
     * Create a new factory instance.
35
     *
36
     * @param  \Illuminate\Contracts\Container\Container  $app
37
     * @param  \Illuminate\Contracts\Cache\Repository  $cache
38
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by Dwight Watson
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
39
     */
40 1
    public function __construct(Container $app, Repository $cache)
41
    {
42 1
        $this->app = $app;
43 1
        $this->cache = $cache;
44 1
    }
45
46
    /**
47
     * Get an instance of the Pushok client, holding on to each in the cache for the given length of time.
48
     *
49
     * @return \Pushok\Client
50
     */
51 1
    public function instance(): Client
52
    {
53 1
        return $this->cache->remember(Client::class, Carbon::now()->addMinutes(static::CACHE_MINUTES), function () {
54 1
            return $this->app->make(Client::class);
55 1
        });
56
    }
57
}
58