juniorb2ss/zServices

View on GitHub
src/Helpers/Sintegra.php

Summary

Maintainability
A
35 mins
Test Coverage
<?php
if (!function_exists('sintegra'))
{
    /**
     * Helper retorna informações do sintegra
     * @SuppressWarnings(PHPMD)
     * @param  integer $document CNPJ or IE
     * @param  string $cookie   cookie request
     * @param  string $captcha  Captcha resolvido
     * @param  array $params
     * @return array
     */
    function sintegra($portal = 'SP', $document = false, $cookie = false, $captcha = false, $params = [])
    {
        /**
         * Inicia a classe
         * @var object \zServices\Sintegra\Services\Portais\{$portal}\Service
         */
        $search = (new \zServices\Sintegra\Search)->service($portal);

        /**
         * @var array data
         */
        if ($document == true && $cookie == true && $captcha == true && count($params) > 0) {
            $crawler = $search->data($document, $cookie, $captcha, $params);

            return $crawler->scraping();
        }

        // Se não retorna requisição inicial
        // com cookie e captcha
        $search->request();

        return  [
            'cookie' => $search->cookie(),
            'image'  => $search->captcha(),
            'paramBot' => $search->params()['parambot']
        ];
    }
}