src/FormatMapping.php
public function article(string $singleJsonArticle): Article
    {
        if (json_decode($singleJsonArticle, true)) {
            $dataArticle = json_decode($singleJsonArticle, true)['data'];

            $article = new Article(

                $this->filterString(
                    $this->getValue('title', $dataArticle)
                ),
                $this->filterString(
                    $this->getValue('body', $dataArticle)
                ),
                $this->filterString(
                    $this->getValue('source', $dataArticle)
                ),
                $this->getValue('unique_id', $dataArticle),
                $this->filterInteger(
                    $this->getValue(
                        'type_id',
                        $dataArticle['type']
                    )
                ),
                $this->filterInteger(
                    $this->getValue(
                        'category_id',
                        $dataArticle['category']
                    )
                ),
                $this->getValue('reporter', $dataArticle),
                $this->filterString(
                    $this->getValue('lead', $dataArticle)
                ),
                $this->getValue('tag_name', $dataArticle['tags']),
                $this->filterString(
                    $this->getValue('published_at', $dataArticle)
                ),
                (string) $this->filterInteger(
                    $this->getValue('id', $dataArticle)
                )
            );

            $attachmentConstants = [
                Article::ATTACHMENT_FIELD_PHOTO,
                Article::ATTACHMENT_FIELD_PAGE,
                Article::ATTACHMENT_FIELD_GALLERY,
                Article::ATTACHMENT_FIELD_VIDEO,
            ];

            $attachmentTypes = [
                self::JSON_PHOTO_FIELD, self::JSON_PAGE_FIELD,
                self::JSON_GALLERY_FIELD, self::JSON_VIDEO_FIELD,
            ];

            $attachmentAttributes = $this->lookUp($attachmentConstants);

            return $this->generalAttachment(
                $article,
                $attachmentConstants,
                $attachmentTypes,
                $attachmentAttributes,
                $dataArticle
            );
        }

        throw new \Exception('Empty or invalid JSON Response', 1);
    }
public function article(string $singleJsonArticle): Article
    {
        if (json_decode($singleJsonArticle, true)) {
            $dataArticle = json_decode($singleJsonArticle, true)['data'];

            $article = new Article(

                $this->filterString(
                    $this->getValue('title', $dataArticle)
                ),
                $this->filterString(
                    $this->getValue('body', $dataArticle)
                ),
                $this->filterString(
                    $this->getValue('source', $dataArticle)
                ),
                $this->getValue('unique_id', $dataArticle),
                $this->filterInteger(
                    $this->getValue(
                        'type_id',
                        $dataArticle['type']
                    )
                ),
                $this->filterInteger(
                    $this->getValue(
                        'category_id',
                        $dataArticle['category']
                    )
                ),
                $this->getValue('reporter', $dataArticle),
                $this->filterString(
                    $this->getValue('lead', $dataArticle)
                ),
                $this->getValue('tag_name', $dataArticle['tags']),
                $this->filterString(
                    $this->getValue('published_at', $dataArticle)
                ),
                (string) $this->filterInteger(
                    $this->getValue('id', $dataArticle)
                )
            );

            $attachmentConstants = [
                Article::ATTACHMENT_FIELD_PHOTO,
                Article::ATTACHMENT_FIELD_PAGE,
                Article::ATTACHMENT_FIELD_GALLERY,
                Article::ATTACHMENT_FIELD_VIDEO,
            ];

            $attachmentTypes = [
                self::JSON_PHOTO_FIELD, self::JSON_PAGE_FIELD,
                self::JSON_GALLERY_FIELD, self::JSON_VIDEO_FIELD,
            ];

            $attachmentAttributes = $this->lookUp($attachmentConstants);

            return $this->generalAttachment(
                $article,
                $attachmentConstants,
                $attachmentTypes,
                $attachmentAttributes,
                $dataArticle
            );
        }

        throw new \Exception('Empty or invalid JSON Response', 1);
    }
public function article ( string $ singleJsonArticle ) : Article { if ( json_decode ( $ singleJsonArticle , true ) ) { $ dataArticle = json_decode ( $ singleJsonArticle , true ) [ 'data' ] ; $ article = new Article ( $ this -> filterString ( $ this -> getValue ( 'title' , $ dataArticle ) ) , $ this -> filterString ( $ this -> getValue ( 'body' , $ dataArticle ) ) , $ this -> filterString ( $ this -> getValue ( 'source' , $ dataArticle ) ) , $ this -> getValue ( 'unique_id' , $ dataArticle ) , $ this -> filterInteger ( $ this -> getValue ( 'type_id' , $ dataArticle [ 'type' ] ) ) , $ this -> filterInteger ( $ this -> getValue ( 'category_id' , $ dataArticle [ 'category' ] ) ) , $ this -> getValue ( 'reporter' , $ dataArticle ) , $ this -> filterString ( $ this -> getValue ( 'lead' , $ dataArticle ) ) , $ this -> getValue ( 'tag_name' , $ dataArticle [ 'tags' ] ) , $ this -> filterString ( $ this -> getValue ( 'published_at' , $ dataArticle ) ) , ( string ) $ this -> filterInteger ( $ this -> getValue ( 'id' , $ dataArticle ) ) ) ; $ attachmentConstants = [ Article :: ATTACHMENT_FIELD_PHOTO , Article :: ATTACHMENT_FIELD_PAGE , Article :: ATTACHMENT_FIELD_GALLERY , Article :: ATTACHMENT_FIELD_VIDEO , ] ; $ attachmentTypes = [ self :: JSON_PHOTO_FIELD , self :: JSON_PAGE_FIELD , self :: JSON_GALLERY_FIELD , self :: JSON_VIDEO_FIELD , ] ; $ attachmentAttributes = $ this -> lookUp ( $ attachmentConstants ) ; return $ this -> generalAttachment ( $ article , $ attachmentConstants , $ attachmentTypes , $ attachmentAttributes , $ dataArticle ) ; } throw new \ Exception ( 'Empty or invalid JSON Response' , 1 ) ; }
map a single article to main attributes in Article Class
@param  string $singleJsonArticle JSON response
@throws Exception
map a single article to main attributes in Article Class