GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( fe4962...3aa77f )
by Thijs
04:04
created

GuzzleClientFactory::getLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace WebservicesNl\Protocol\Soap\Helper;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\HandlerStack;
7
use GuzzleHttp\MessageFormatter;
8
use GuzzleHttp\Middleware;
9
use Psr\Log\LoggerAwareTrait;
10
use Psr\Log\LoggerInterface;
11
use WebservicesNl\Connector\Client\ClientFactoryInterface;
12
use WebservicesNl\Platform\PlatformConfigInterface;
13
14
/**
15
 * HttpClientFactory.
16
 * Helper class the Webservices connector generator with instantiating a PSR-7 curl client.
17
 */
18
class GuzzleClientFactory implements ClientFactoryInterface
19
{
20
    use LoggerAwareTrait;
21
22
    /**
23
     * @var PlatformConfigInterface
24
     */
25
    private $platform;
26
27
    /**
28
     * HttpClientFactory constructor.
29
     *
30
     * @param PlatformConfigInterface $platform
31
     * @param LoggerInterface|null    $logger
32
     */
33
    public function __construct(PlatformConfigInterface $platform, LoggerInterface $logger = null)
34
    {
35
        $this->platform = $platform;
36
        $this->logger = $logger;
37
    }
38
39
    /**
40
     * Create a static instance (LSB) of HttpClientFactory.
41
     *
42
     * @param PlatformConfigInterface $platform
43
     * @param LoggerInterface         $logger
44
     *
45
     * @return GuzzleClientFactory
46
     */
47
    public static function build(PlatformConfigInterface $platform, LoggerInterface $logger = null)
48
    {
49
        return new static($platform, $logger);
50
    }
51
52
    /**
53
     * Create and configure a http curl client.
54
     *
55
     * @param array $settings additional settings
56
     *
57
     * @return Client
58
     */
59
    public function create(array $settings = [])
60
    {
61
        $stack = null;
62
        $settings = $this->platform->toArray() + $settings;
63
64
        if ($this->getLogger() instanceof LoggerInterface) {
65
            $stack = HandlerStack::create();
66
            $stack->push(Middleware::log($this->getLogger(), new MessageFormatter('{request} - {response}')));
67
        }
68
69
        return new Client(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \GuzzleHttp\C...'connectionTimeout'])); (GuzzleHttp\Client) is incompatible with the return type declared by the interface WebservicesNl\Connector\...actoryInterface::create of type WebservicesNl\Connector\Client\ClientInterface.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
70
            [
71
                'base_url'           => (string)$settings['url'],
72
                'handler'            => $stack,
73
                'exceptions'         => (bool)$settings['exceptions'],
74
                'timeout'            => (float)$settings['responseTimeout'],
75
                'connection_timeout' => (float)$settings['connectionTimeout'],
76
            ]
77
        );
78
    }
79
80
    /**
81
     * Returns this LoggerInterface
82
     *
83
     * @return LoggerInterface
84
     */
85
    public function getLogger()
86
    {
87
        return $this->logger;
88
    }
89
}
90