hughcube-php /
laravel-wechat
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * Created by PhpStorm. |
||||
| 4 | * User: hugh.li |
||||
| 5 | * Date: 2022/2/24 |
||||
| 6 | * Time: 23:11 |
||||
| 7 | */ |
||||
| 8 | |||||
| 9 | namespace HughCube\Laravel\WeChat\Message\Event; |
||||
| 10 | |||||
| 11 | use Carbon\Carbon; |
||||
| 12 | |||||
| 13 | class Event implements \HughCube\Laravel\WeChat\Contracts\Message\Event\Event |
||||
| 14 | { |
||||
| 15 | /** |
||||
| 16 | * @var array |
||||
| 17 | */ |
||||
| 18 | protected $message; |
||||
| 19 | |||||
| 20 | /** |
||||
| 21 | * @param array $message |
||||
| 22 | */ |
||||
| 23 | public function __construct(array $message = []) |
||||
| 24 | { |
||||
| 25 | $this->message = $message; |
||||
| 26 | } |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * @param string|null $key |
||||
| 30 | * @return array|mixed|null |
||||
| 31 | */ |
||||
| 32 | public function getMessage(?string $key = null) |
||||
| 33 | { |
||||
| 34 | if (null === $key) { |
||||
| 35 | return $this->message; |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | return $this->message[$key] ?? null; |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | public function getToUserName(): ?string |
||||
| 42 | { |
||||
| 43 | return $this->getMessage('ToUserName'); |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 44 | } |
||||
| 45 | |||||
| 46 | public function getFromUserName(): ?string |
||||
| 47 | { |
||||
| 48 | return $this->getMessage('FromUserName'); |
||||
|
0 ignored issues
–
show
|
|||||
| 49 | } |
||||
| 50 | |||||
| 51 | public function getMessageType(): ?string |
||||
| 52 | { |
||||
| 53 | return $this->getMessage('MsgType'); |
||||
|
0 ignored issues
–
show
|
|||||
| 54 | } |
||||
| 55 | |||||
| 56 | public function getCreatedAt(): ?Carbon |
||||
| 57 | { |
||||
| 58 | $timestamp = $this->getMessage('CreateTime'); |
||||
| 59 | if (empty($timestamp)) { |
||||
| 60 | return null; |
||||
| 61 | } |
||||
| 62 | return Carbon::createFromTimestamp($timestamp); |
||||
|
0 ignored issues
–
show
It seems like
$timestamp can also be of type array; however, parameter $timestamp of Carbon\Carbon::createFromTimestamp() does only seem to accept double|integer|string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 63 | } |
||||
| 64 | |||||
| 65 | public function getMessageId(): ?int |
||||
| 66 | { |
||||
| 67 | return $this->getMessage('MsgId') ?: $this->getMessage('MsgID'); |
||||
|
0 ignored issues
–
show
|
|||||
| 68 | } |
||||
| 69 | |||||
| 70 | public function getEvent(): ?string |
||||
| 71 | { |
||||
| 72 | return $this->getMessage('Event'); |
||||
|
0 ignored issues
–
show
|
|||||
| 73 | } |
||||
| 74 | |||||
| 75 | public function getEventKey() |
||||
| 76 | { |
||||
| 77 | return $this->getMessage('EventKey'); |
||||
| 78 | } |
||||
| 79 | |||||
| 80 | public function getOpenID(): ?string |
||||
| 81 | { |
||||
| 82 | return $this->getFromUserName(); |
||||
| 83 | } |
||||
| 84 | } |
||||
| 85 |