AttributeWriter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Actualys\Bundle\DrupalCommerceConnectorBundle\Writer;
4
5
use Actualys\Bundle\DrupalCommerceConnectorBundle\Item\DrupalItemStep;
6
use Akeneo\Bundle\BatchBundle\Item\ItemWriterInterface;
7
use Akeneo\Bundle\BatchBundle\Event\InvalidItemEvent;
8
use Symfony\Component\EventDispatcher\EventDispatcher;
9
use Akeneo\Bundle\BatchBundle\Event\EventInterface;
10
11 View Code Duplication
class AttributeWriter extends DrupalItemStep implements ItemWriterInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    protected $eventDispatcher;
14
15
    public function __construct(EventDispatcher $eventDispatcher)
16
    {
17
        $this->eventDispatcher = $eventDispatcher;
18
    }
19
20
    /**
21
     * @param array $items
22
     */
23
    public function write(array $items)
24
    {
25
        //file_put_contents('attribute.json', json_encode($items));
26
        foreach ($items as $item) {
27
            try {
28
                 $this->webservice->sendAttribute($item);
0 ignored issues
show
Bug introduced by
The method sendAttribute() does not exist on Actualys\Bundle\DrupalCo...e\Webservice\Webservice. Did you maybe mean sendAttributeOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
29
            } catch (\Exception $e) {
30
                $event = new InvalidItemEvent(
31
                  __CLASS__,
32
                  $e->getMessage(),
33
                  array(),
34
                  ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL']
35
                );
36
                // Logging file
37
                $this->eventDispatcher->dispatch(
38
                  EventInterface::INVALID_ITEM,
39
                  $event
40
                );
41
42
43
                // Loggin Interface
44
                $this->stepExecution->addWarning(
45
                  __CLASS__,
46
                  $e->getMessage(),
47
                  array(),
48
                  ['code' => array_key_exists('code', $item) ? $item['code'] : 'NULL']
49
                );
50
51
                /** @var ClientErrorResponseException  $e */
52
                if ($e->getResponse()->getStatusCode() <= 404) {
53
                    $e = new \Exception($e->getResponse()->getReasonPhrase());
54
                    $this->stepExecution->addFailureException($e);
55
                    $exitStatus = new ExitStatus(ExitStatus::FAILED);
56
                    $this->stepExecution->setExitStatus($exitStatus);
57
                }
58
                // Handle next element.
59
            }
60
            $this->stepExecution->incrementWriteCount();
61
            $this->stepExecution->incrementSummaryInfo('write');
62
63
        }
64
    }
65
}
66