Passed
Push — master ( de9f16...6836c0 )
by Aleksandr
02:35
created

helpers/SerializeHelper.php (2 issues)

Labels
Severity
1
<?php
2
3
4
namespace carono\exchange1c\helpers;
5
6
7
use carono\exchange1c\interfaces\DocumentInterface;
8
use carono\exchange1c\interfaces\OfferInterface;
9
use carono\exchange1c\interfaces\PartnerInterface;
10
use carono\exchange1c\interfaces\ProductInterface;
11
12
class SerializeHelper
13
{
14
    public static function serializePartner(PartnerInterface $partner)
15
    {
16
        $xml = new \SimpleXMLElement('<Контрагент></Контрагент>');
17
        self::addFields($xml, $partner, $partner->getExportFields1c());
18
        foreach ($partner::getFields1c() as $field1c => $attribute) {
0 ignored issues
show
The method getFields1c() does not exist on carono\exchange1c\interfaces\PartnerInterface. Did you maybe mean getExportFields1c()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        foreach ($partner::/** @scrutinizer ignore-call */ getFields1c() as $field1c => $attribute) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
            if ($attribute) {
20
                $xml->addChild($field1c, $partner->{$attribute});
21
            }
22
        }
23
        return $xml;
24
    }
25
26
    public static function serializeOffer(OfferInterface $offer, DocumentInterface $document)
27
    {
28
        $productNode = new \SimpleXMLElement('<Товар></Товар>');
29
        self::addFields($productNode, $offer, $offer->getExportFields1c($document));
30
        if ($group = $offer->getGroup1c()) {
31
            $productNode->addChild('ИдКаталога', $group->getId1c());
0 ignored issues
show
The method getId1c() does not exist on carono\exchange1c\interfaces\GroupInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            $productNode->addChild('ИдКаталога', $group->/** @scrutinizer ignore-call */ getId1c());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
        }
33
        return $productNode;
34
    }
35
36
37
    public static function serializeDocument(DocumentInterface $document)
38
    {
39
        $documentNode = new \SimpleXMLElement('<Документ></Документ>');
40
        self::addFields($documentNode, $document, $document->getExportFields1c());
41
        $partnersNode = $documentNode->addChild('Контрагенты');
42
        $partner = $document->getPartner1c();
43
        $partnerNode = self::serializePartner($partner);
44
        NodeHelper::appendNode($partnersNode, $partnerNode);
45
        $products = $documentNode->addChild('Товары');
46
        foreach ($document->getOffers1c() as $offer) {
47
            $productNode = self::serializeOffer($offer, $document);
48
            NodeHelper::appendNode($products, $productNode);
49
        }
50
        return $documentNode;
51
    }
52
53
    public static function addFields($node, $object, $fields)
54
    {
55
        foreach ($fields as $field => $value) {
56
            NodeHelper::addChild($node, $object, $field, $value);
57
        }
58
    }
59
60
}