Completed
Pull Request — master (#32)
by Sergey
04:49 queued 01:06
created

Bot::__get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace seregazhuk\PinterestBot;
4
5
use LogicException;
6
use seregazhuk\PinterestBot\Api\Providers\Pins;
7
use seregazhuk\PinterestBot\Api\Providers\Boards;
8
use seregazhuk\PinterestBot\Api\Providers\Pinners;
9
use seregazhuk\PinterestBot\Api\Providers\Provider;
10
use seregazhuk\PinterestBot\Api\Providers\Interests;
11
use seregazhuk\PinterestBot\Api\Providers\Conversations;
12
use seregazhuk\PinterestBot\Contracts\ProvidersContainerInterface;
13
14
/**
15
 * Class Bot
16
 *
17
 * @package Pinterest
18
 * @property string        $username
19
 * @property string        $password
20
 * @property Pinners       $pinners
21
 * @property Pins          $pins
22
 * @property Boards        $boards
23
 * @property Interests     $interests
24
 * @property Conversations $conversations
25
 */
26
class Bot
27
{
28
    /**
29
     * @var ProvidersContainerInterface
30
     */
31
    private $providersContainer;
32
33
    public function __construct(ProvidersContainerInterface $providersContainer)
34
    {
35
        $this->providersContainer = $providersContainer;
36
    }
37
38
    /**
39
     * Proxy method to pinners login
40
     * @param string $username
41
     * @param string $password
42
     * @return bool
43
     */
44
    public function login($username, $password)
45
    {
46
        return $this->pinners->login($username, $password);
47
    }
48
49
    /**
50
     * @param string $provider
51
     * @return Provider
52
     */
53
    public function __get($provider)
54
    {
55
        $provider = strtolower($provider);
56
57
        return $this->providersContainer->getProvider($provider);
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getLastError()
64
    {
65
        return $this->providersContainer->getResponse()->getLastError();
66
    }
67
}