FMeatClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getCurrentWeekForLocation() 0 5 1
A getNextWeekForLocation() 0 5 1
1
<?php
2
3
namespace JPBernius\FMeat;
4
5
use JPBernius\FMeat\Configurations\Locations;
6
use JPBernius\FMeat\Entities\Week;
7
use JPBernius\FMeat\Services\CachedNetworkService;
8
use JPBernius\FMeat\Services\NetworkService;
9
use JPBernius\FMeat\Utilities\YearWeekUtil;
10
use DI\ContainerBuilder;
11
12
/**
13
 * Class FMeatClient
14
 * @package JPBernius\FMeat
15
 */
16
class FMeatClient
17
{
18
    /** @var NetworkService */
19
    private $networkService;
20
21
    /** @var YearWeekUtil */
22
    private $yearWeekUtil;
23
24
    /**
25
     * FMeatClient constructor.
26
     * @param bool $useCaching
27
     * @throws \DI\DependencyException
28
     * @throws \DI\NotFoundException
29
     */
30
    public function __construct(bool $useCaching = false)
31
    {
32
        $container = ContainerBuilder::buildDevContainer();
33
        $this->yearWeekUtil = $container->get(YearWeekUtil::class);
34
35
        if ($useCaching) {
36
            $this->networkService = $container->get(CachedNetworkService::class);
37
        } else {
38
            $this->networkService = $container->get(NetworkService::class);
39
        }
40
    }
41
42
    /**
43
     * @param string $location
44
     * @return Week
45
     * @throws Exeptions\NetworkingException
46
     */
47
    public function getCurrentWeekForLocation(string $location = Locations::FMI_BISTRO): Week
48
    {
49
        $currentWeek = $this->yearWeekUtil->getCurrentCalendarWeek();
50
        return $this->networkService->getWeekWithLocation($currentWeek, $location);
51
    }
52
53
    /**
54
     * @param string $location
55
     * @return Week
56
     * @throws Exeptions\NetworkingException
57
     */
58
    public function getNextWeekForLocation(string $location = Locations::FMI_BISTRO): Week
59
    {
60
        $nextWeek = $this->yearWeekUtil->getNextCalendarWeek();
61
        return $this->networkService->getWeekWithLocation($nextWeek, $location);
62
    }
63
}