MessageFactory::entity()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Polidog\Chatwork\Entity\Factory;
6
7
use Cake\Utility\Inflector;
8
use Polidog\Chatwork\Entity\Message;
9
10
class MessageFactory extends AbstractFactory
11
{
12
    /**
13
     * @param array $data
14
     *
15
     * @return Message
16
     */
17
    public function entity(array $data = [])
18
    {
19
        // @todo ここでnewするのなんとかしたい・・・
20
        $userFactory = new UserFactory();
21
        $message = new Message();
22
23
        $message->account = $userFactory->entity($data['account']);
24
        unset($data['account']);
25
26
        foreach ($data as $key => $value) {
27
            $property = Inflector::variable($key);
28
            $message->$property = $value;
29
        }
30
31
        return $message;
32
    }
33
}
34