Passed
Push — master ( eac84f...04da79 )
by Tomasz
01:29
created

UseCase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 15 2
1
<?php
2
/**
3
 *
4
 * This file is part of the Aggrego.
5
 * (c) Tomasz Kunicki <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
namespace Aggrego\Neo4jIntegration\Api\Command\CreateNode;
13
14
use GraphAware\Neo4j\Client\Client;
15
use GraphAware\Neo4j\Client\Exception\Neo4jExceptionInterface;
16
17
class UseCase
18
{
19
    /** @var Client */
20
    private $client;
21
22
    public function __construct(Client $client)
23
    {
24
        $this->client = $client;
25
    }
26
27
    public function handle(Command $command): Response
28
    {
29
        try {
30
            $this->client->run(
31
                'CREATE (n:{node}) SET n += {data}',
32
                [
33
                    'node' => $command->getNodeName(),
34
                    'data' => $command->getData(),
35
                ]
36
            );
37
        } catch (Neo4jExceptionInterface $e) {
38
            return Response::fail($e->getMessage());
39
        }
40
41
        return Response::ok();
42
    }
43
}
44