1 | <?php |
||
11 | class Phlack extends Collection |
||
12 | { |
||
13 | /** |
||
14 | * Phlack Constructor. |
||
15 | * |
||
16 | * @param mixed $client |
||
17 | * |
||
18 | * @throws UnexpectedTypeException |
||
19 | */ |
||
20 | 15 | public function __construct($client) |
|
21 | { |
||
22 | 15 | if (is_string($client) || is_array($client)) { |
|
23 | 2 | $client = new PhlackClient($client); |
|
|
|||
24 | 13 | } elseif (!$client instanceof PhlackClient) { |
|
25 | 1 | throw new UnexpectedTypeException($client, ['string', 'array', 'Crummy\Phlack\Bridge\Guzzle\PhlackClient']); |
|
26 | } |
||
27 | |||
28 | 14 | parent::__construct([ |
|
29 | 14 | 'client' => $client, |
|
30 | 'builders' => [], |
||
31 | 'commands' => [ |
||
32 | 'send' => 'Send', |
||
33 | ], |
||
34 | ]); |
||
35 | 14 | } |
|
36 | |||
37 | /** |
||
38 | * Phlack Factory. |
||
39 | * |
||
40 | * @param array|string $config |
||
41 | * |
||
42 | * @return Phlack |
||
43 | */ |
||
44 | 2 | public static function factory($config = []) |
|
45 | { |
||
46 | 2 | return new self(new PhlackClient($config)); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return Phlack |
||
51 | */ |
||
52 | 1 | public static function fromConfig(array $config = [], array $defaults = [], array $required = []) |
|
56 | |||
57 | /** |
||
58 | * @param string|array|JsonSerializable $message |
||
59 | * |
||
60 | * @throws UnexpectedTypeException |
||
61 | * |
||
62 | * @return MessageResponse |
||
63 | */ |
||
64 | 5 | public function send($message) |
|
68 | |||
69 | /** |
||
70 | * @return Bridge\Guzzle\PhlackClient |
||
71 | */ |
||
72 | 6 | public function getClient() |
|
73 | { |
||
74 | 6 | return $this['client']; |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * @return Builder\MessageBuilder |
||
79 | */ |
||
80 | 2 | public function getMessageBuilder() |
|
81 | { |
||
82 | 2 | if (!isset($this['builders']['message'])) { |
|
83 | 2 | $this->setPath('builders/message', new Builder\MessageBuilder()); |
|
84 | } |
||
85 | |||
86 | 2 | return $this['builders']['message']; |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * @return Builder\AttachmentBuilder |
||
91 | */ |
||
92 | 1 | public function getAttachmentBuilder() |
|
93 | { |
||
94 | 1 | if (!isset($this['builders']['attachment'])) { |
|
95 | 1 | $this->setPath('builders/attachment', new Builder\AttachmentBuilder()); |
|
96 | } |
||
97 | |||
98 | 1 | return $this['builders']['attachment']; |
|
99 | } |
||
100 | |||
101 | /** |
||
102 | * @param mixed $message |
||
103 | * |
||
104 | * @throws UnexpectedTypeException |
||
105 | * |
||
106 | * @return array |
||
107 | */ |
||
108 | 5 | private function toParameters($message) |
|
120 | } |
||
121 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.