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.

Foaas   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 5
dl 0
loc 124
ccs 48
cts 48
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B __call() 0 36 6
A getOperations() 0 25 3
A callFoaas() 0 9 2
A operations() 0 4 1
1
<?php
2
3
namespace Foaas;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
7
/**
8
 * Fuck off as a Service.
9
 *
10
 * Because fuck you. That's why. (Seriously, this is probably the best remote
11
 * service ever.)
12
 *
13
 * @method Response off(string $name, string $from) Fuck off, :name. - :from
14
 * @method Response ing(string $name, string $from) Fucking fuck off, :name. - :from
15
 * @method Response you(string $name, string $from) Fuck you, :name. - :from
16
 * @method Response this(string $from) Fuck this. - :from
17
 * @method Response that(string $from) Fuck that. - :from
18
 * @method Response everything(string $from) Fuck everything. - :from
19
 * @method Response everyone(string $from) Everyone can go and fuck off. - :from
20
 * @method Response donut(string $name, string $from) :name, go and take a flying fuck at a rolling donut. - :from
21
 * @method Response shakespeare(string $name, string $from) :name, Thou clay-brained guts, thou knotty-pated fool, thou whoreson obscene greasy tallow-catch! - :from
22
 * @method Response linus(string $name, string $from) :name, there aren't enough swear-words in the English language, so now I'll have to call you perkeleen vittupää just to express my disgust and frustration with this crap. - :from
23
 * @method Response king(string $name, string $from) Oh fuck off, just really fuck off you total dickface. Christ :name, you are fucking thick. - :from
24
 * @method Response pink(string $from) Well, Fuck me pink. - :from
25
 * @method Response life(string $from) Fuck my life. - :from
26
 * @method Response chainsaw(string $name, string $from) Fuck me gently with a chainsaw, :name. Do I look like Mother Teresa? - :from
27
 * @method Response outside(string $name, string $from) :name, why don't you go outside and play hide-and-go-fuck-yourself? - :from
28
 * @method Response thanks(string $from) Fuck you very much. - :from
29
 * @method Response flying(string $from) I don't give a flying fuck. - :from
30
 * @method Response fascinating(string $from) Fascinating story, in what chapter do you shut the fuck up? - :from
31
 * @method Response madison(string $name, string $from) What you've just said is one of the most insanely idiotic things I have ever heard, :name. At no point in your rambling, incoherent response were you even close to anything that could be considered a rational thought. Everyone in this room is now dumber for having listened to it. I award you no points :name, and may God have mercy on your soul. - :from
32
 * @method Response cool(string $from) Cool story, Bro - :from
33
 * @method Response field(string $name, string $from, string $reference) And :name said unto :from, "Verily, cast thine eyes upon the field in which I grow my fucks", and :from gave witness unto the field, and saw that it was barren. - :reference
34
 * @method Response nugget(string $name, string $from) Well :name, aren't you a shining example of a rancid fuck-nugget. - :from
35
 * @method Response yoda(string $name, string $from) Fuck off, you must, :name. - :from
36
 * @method Response ballmer(string $name, string $company, string $from) Fucking :name is a fucking pussy. I'm going to fucking bury that guy, I have done it before, and I will do it again. I'm going to fucking kill :company. - :from
37
 * @method Response what(string $from) What the fuck?!. - :from
38
 * @method Response because(string $from) Why? Because Fuck you, that's why. - :from
39
 * @method Response caniuse(string $tool, string $from) Can you use :tool? Fuck no! - :from
40
 * @method Response bye(string $from) Fuckity bye! - :from
41
 * @method Response diabetes(string $from) I'd love to stop and chat to you but I'd rather have type 2 diabetes. - :from
42
 * @method Response bus(string $name, string $from) Christ on a bendy-bus, :name, don't be such a fucking faff-arse. - :from
43
 * @method Response xmas(string $name, string $from) Merry Fucking Christmas, :name. - :from
44
 * @method Response bday(string $name, string $from) Happy Fucking Birthday, :name. - :from
45
 * @method Response awesome(string $from) This is Fucking Awesome. - :from
46
 * @method Response tucker(string $from) Come the fuck in or fuck the fuck off. - :from
47
 * @method Response bucket(string $from) Please choke on a bucket of cocks. - :from
48
 * @method Response family(string $from) Fuck you, your whole family, your pets, and your feces. - :from
49
 * @method Response shutup(string $name, string $from) :name, shut the fuck up. - :from
50
 * @method Response zayn(string $from) Ask me if I give a motherfuck ?!! - :from
51
 * @method Response keepcalm(string $reaction, string $from) Keep the fuck calm and :reaction! - :from
52
 * @method Response dosomething(string $do, string $something, string $from) :do the fucking :something! - :from
53
 * @method Response mornin(string $from) Happy fuckin' Mornin'! - :from
54
 * @method Response thumbs(string $name, string $from) Who has two thumbs and doesn't give a fuck? :name. - :from
55
 * @method Response retard(string $from) You Fucktard! - :from
56
 * @method Response greed(string $noun, string $from) The point is, ladies and gentleman, that :noun -- for lack of a better word -- is good. :noun is right. :noun works. :noun clarifies, cuts through, and captures the essence of the evolutionary spirit. :noun, in all of its forms -- :noun for life, for money, for love, knowledge -- has marked the upward surge of mankind - :from
57
 * @method Response bm(string $name, string $from) Bravo mike, :name. - :from
58
 * @method Response gfy(string $name, string $from) Golf foxtrot yankee, :name. - :from
59
 * @method Response me(string $from) Fuck me. - :from
60
 * @method Response back(string $name, string $from) :name, back the fuck off. - :from
61
 * @method Response think(string $name, string $from) :name, you think I give a fuck? - :from
62
 * @method Response keep(string $name, string $from) :name: Fuck off. And when you get there, fuck off from there too. Then fuck off some more. Keep fucking off until you get back here. Then fuck off again. - :from
63
 * @method Response single(string $from) Not a single fuck was given. - :from
64
 * @method Response thinking(string $name, string $from) :name, what the fuck where you actually thinking? - :from
65
 * @method Response looking(string $from) Looking for a fuck to give. - :from
66
 * @method Response no(string $from) No fucks given. - :from
67
 * @method Response give(string $from) I give zero fucks. - :from
68
 * @method Response zero(string $from) Zero, thats the number of fucks I give. - :from
69
 * @method Response pulp(string $language, string $from) :language, motherfucker, do you speak it? - :from
70
 * @method Response sake(string $from) For Fuck's sake! - :from
71
 * @method Response particular(string $thing, string $from) Fuck this :thing in particular. - :from
72
 * @method Response anyway(string $company, string $from) Who the fuck are you anyway, :company, why are you stirring up so much trouble, and, who pays you? - :from
73
 * @method Response maybe(string $from) Maybe. Maybe not. Maybe fuck yourself. - :from
74
 * @method Response blackadder(string $name, string $from) :name, your head is as empty as a eunuch’s underpants. Fuck off! - :from
75
 * @method Response horse(string $from) Fuck you and the horse you rode in on. - :from
76
 * @method Response deraadt(string $name, string $from) :name you are being the usual slimy hypocritical asshole... You may have had value ten years ago, but people will see that you don't anymore. - :from
77
 * @method Response problem(string $name, string $from) What the fuck is you problem :name? - :from
78
 * @method Response cocksplat(string $name, string $from) Fuck off :name, you worthless cocksplat. - :from
79
 * @method Response too(string $from) Thanks, fuck you too. - :from
80
 * @method Response {'off-with'}(string $behavior, string $from) Fuck off with :behavior - :from
81
 * @method Response version() Get the FOAAS service version.
82
 *
83
 * @link http://foaas.com/
84
 * @link https://github.com/xenph/foaas
85
 */
86
class Foaas extends GuzzleClient
87
{
88
    /**
89
     * Fuck. Better make an FOAAS call.
90
     *
91
     * @param array $config Overrides to the default config.
92
     */
93 5
    public function __construct(array $config = [])
94
    {
95
        $defaultConfig = [
96 5
            'base_uri' => 'https://foaas.herokuapp.com',
97
            'headers' => [
98 5
                'Accept' => 'application/json',
99 5
            ],
100 5
        ];
101
102 5
        parent::__construct(array_replace_recursive($defaultConfig, $config));
103 5
    }
104
105
    /**
106
     * Make a fucking FOAAS HTTP request.
107
     *
108
     * @throws Exception if you didn't pass enough arguments. Way to go, dingus.
109
     * @throws Exception if you fucked up and passed too many arguments.
110
     * @param string $method
111
     * @param array $args
112
     * @return Response
113
     */
114 4
    public function __call($method, $args)
115
    {
116 4
        $missingArguments = [];
117 4
        $tooManyArguments = false;
118 4
        $operations = $this->getOperations();
119
120
        // Make sure the right number of fields were passed in.
121
        // Custom FOAAS calls have :thing and :from fields
122 4
        $customCallArguments = ['from'];
123 4
        $requiredArguments = in_array($method, array_keys($operations))
124 4
            ? $operations[$method]
125 4
            : $customCallArguments;
126
127 4
        $countDiff = count($args) - count($requiredArguments);
128
129
        // Figure out which arguments were missing or if there were too many
130
        // arguments.
131 4
        if ($countDiff < 0) {
132 1
            $missingArguments = array_splice($requiredArguments, count($args) * -1);
133 4
        } elseif ($countDiff > 0) {
134 1
            $tooManyArguments = true;
135 1
        }
136
137
        // Hey fucko, ya missed something.
138 4
        if (!empty($missingArguments)) {
139 1
            throw new Exception('Missing the arguments: ' . implode(', ', $missingArguments) . '.');
140
        }
141
142
        // How do I hold all these arguments?
143 3
        if ($tooManyArguments) {
144 1
            throw new Exception('Too many arguments!');
145
        }
146
147
        // Finally, make the damn FOAAS call.
148 2
        return $this->callFoaas('/' . $method . '/' . implode('/', $args));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->callFoaas(.... implode('/', $args)); (Foaas\Response) is incompatible with the return type of the parent method GuzzleHttp\Client::__call of type GuzzleHttp\Promise\Promi...ssage\ResponseInterface.

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...
149
    }
150
151
    /**
152
     * Grab the stupid operations list from FOAAS and turn it into a operation
153
     * name => fields array for the calling code.
154
     *
155
     * @return array
156
     */
157 4
    protected function getOperations()
158
    {
159
        // Cache the FOAAS call names and required parameters.
160 4
        static $operations = [];
161
162 4
        if (!empty($operations)) {
163 3
            return $operations;
164
        }
165
166
        // Separate available operations into name/fields pairs.
167 1
        foreach ($this->operations() as $operation) {
168 1
            $operationName = explode('/', $operation['url'])[1];
169 1
            $fields = array_map(
170 1
                function($field)
171
                {
172 1
                    return $field['field'];
173 1
                },
174 1
                $operation['fields']
175 1
            );
176
177 1
            $operations[$operationName] = $fields;
178 1
        }
179
180 1
        return $operations;
181
    }
182
183
    /**
184
     * Make a fucking FOAAS HTTP request.
185
     *
186
     * @throws Exception if FOAAS is giving us shit.
187
     * @param string $path
188
     * @return Response
189
     */
190 2
    protected function callFoaas($path = '/')
191
    {
192
        try {
193 2
            $response = json_decode($this->request('GET', $path)->getBody()->getContents(), true);
194 2
            return new Response($response['message'], $response['subtitle']);
195 1
        } catch (\Exception $e) {
196 1
            throw new Exception($e->getMessage(), $e->getCode(), $e);
197
        }
198
    }
199
200
    /**
201
     * Get a list of all the fucking available FOAAS operations.
202
     *
203
     * @return array
204
     */
205 1
    public function operations()
206
    {
207 1
        return json_decode($this->request('GET', 'operations')->getBody(), true);
208
    }
209
}
210