MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/artinside/public_html/finance/vendor/frenet/frenet-php/src/Service/Result.php
<?php

declare(strict_types = 1);

namespace Frenet\Service;

use Frenet\Framework\Http\Response\ResponseInterface;
use Frenet\Framework\Object\FactoryInterface;
use Frenet\Framework\Object\GodFactory;

/**
 * Class Result
 * @package Frenet\Service
 */
class Result implements ResultInterface
{
    /**
     * @var ResponseInterface
     */
    private $response;

    /**
     * @var GodFactory
     */
    private $godFactory;

    /**
     * @var string
     */
    private $objectTypeClass;

    /**
     * Result constructor.
     *
     * @param GodFactory        $godFactory
     * @param ResponseInterface $response
     * @param string            $objectTypeClass
     */
    public function __construct(
        GodFactory $godFactory,
        ResponseInterface $response,
        $objectTypeClass = null
    ) {
        $this->godFactory = $godFactory;
        $this->response = $response;
        $this->objectTypeClass = $objectTypeClass;
    }

    /**
     * {@inheritdoc}
     */
    public function getResponse()
    {
        return $this->response;
    }

    /**
     * {@inheritdoc}
     */
    public function parse()
    {
        if (!$this->response->canParse() || empty($this->objectTypeClass)) {
            return false;
        }

        /** @var array $body */
        $body = $this->getResponse()->getBody();

        $objectType = $this->godFactory->createObject($this->objectTypeClass, [
            'data' => $body['result']
        ]);

        return $objectType;
    }
}