Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

type checking exception raised in php8 #38

Merged
merged 2 commits into from
Feb 9, 2023
Merged

Conversation

maurobn
Copy link
Contributor

@maurobn maurobn commented Apr 14, 2021

PR to execute the package in PHP8.

@maurobn
Copy link
Contributor Author

maurobn commented Apr 14, 2021

A tiny adjustment in order to be able to execute the package in php8

@maurobn maurobn closed this Apr 14, 2021
@maurobn maurobn reopened this Apr 14, 2021
@codecov-io
Copy link

codecov-io commented Apr 14, 2021

Codecov Report

Merging #38 (6d96518) into develop (0d2e50c) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop      #38   +/-   ##
==========================================
  Coverage      97.45%   97.45%           
  Complexity       121      121           
==========================================
  Files              5        5           
  Lines            275      275           
==========================================
  Hits             268      268           
  Misses             7        7           
Impacted Files Coverage Δ Complexity Δ
src/AbstractStructArrayBase.php 100.00% <100.00%> (ø) 32.00 <6.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d2e50c...6d96518. Read the comment docs.

@@ -251,15 +251,15 @@ private function getInternArrayOffset(): int
* @param bool $internCall indicates that methods is calling itself
* @return AbstractStructArrayBase
*/
private function initInternArray(array $array = [], bool $internCall = false): self
private function initInternArray($array = [], bool $internCall = false): self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not supposed to be anything else than an array if the class inheriting from it is defined as expected. To be discusssed within the WsdlToPhp/PackageGenerator#248 issue

Copy link
Contributor Author

@maurobn maurobn Apr 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As can be seen below, the generated class (ArrayDadosFuncionais) is a child (extends) of AbstractStructArrayBase This class (ArrayDadosFuncionais) when initialized, calls the function initInternArray with no parameters, which in turn calls the same function again with $this->getPropertyValue($this->getAttributeName()) as the first parameter. This parameter is resolved (please, see the code below) in the "dadosFuncionais" which is typed as \SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayOfDadosFuncionais (other generated class).

The attribute $dadosFuncionais, typed as ArrayOfDadosFuncionais, extends AbstractStructArrayBase, which in turn implements StructArrayInterface (StructInterface, ArrayAccess, Iterator, Traversable, Countable, iterable), StructInterface, JsonSerializable.

And when this occurs this exceptions is raised:

WsdlToPhp\PackageBase\AbstractStructArrayBase::initInternArray(): Argument #1 ($array) must be of type array, SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayOfDadosFuncionais given, called in /app/vendor/wsdltophp/packagebase/src/AbstractStructArrayBase.php on line 262

namespace SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ServiceType;
use SoapFault;`
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosBancarios;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosDDP;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosDependentes;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosFuncionais;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosPA;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosRepresentanteLegal;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosSICAJ as ArrayDadosSICAJAlias;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayDadosUorg;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayOfArrayDadosAfastamento;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayOfArrayDadosFinanceiros;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayPensaoRecebida;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayPensoesInstituidas;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\ArrayDadosAfastamento;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\ArrayDadosFinanceiros;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\DadosCurriculo;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\DadosDocumentacao;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\DadosEnderecoResidencial;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\DadosEscolares;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\DadosPessoais;
use SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\StructType\TotalVagasOrgao;
use \WsdlToPhp\PackageBase\AbstractSoapClientBase;

/**

  • This class stands for Consulta ServiceType

  • @subpackage Services
    */
    class Consulta extends AbstractSoapClientBase
    {

    /**

    • Method to call the operation originally named consultaDadosFuncionais
    • @uses AbstractSoapClientBase::getSoapClient()
    • @uses AbstractSoapClientBase::setResult()
    • @uses AbstractSoapClientBase::getResult()
    • @uses AbstractSoapClientBase::saveLastError()
    • @param string $siglaSistema
    • @param string $nomeSistema
    • @param string $senha
    • @param string $cpf
    • @param string $codOrgao
    • @param string $parmExistPag
    • @param string $parmTipoVinculo
    • @return ArrayDadosFuncionais|bool
      */
      public function consultaDadosFuncionais(string $siglaSistema, string $nomeSistema, string $senha, string $cpf, string $codOrgao, string $parmExistPag, string $parmTipoVinculo): ArrayDadosFuncionais|bool
      {
      try {
      $this->setResult($this->getSoapClient()->consultaDadosFuncionais($siglaSistema, $nomeSistema, $senha, $cpf, $codOrgao, $parmExistPag, $parmTipoVinculo));
      return $this->getResult();
      } catch (SoapFault $soapFault) {
      $this->saveLastError(METHOD, $soapFault);
      return false;
      }
      }

=============================================================
namespace SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType;
use WsdlToPhp\PackageBase\AbstractStructArrayBase;

/**

  • This class stands for ArrayDadosFuncionais ArrayType
  • @subpackage Arrays
    /
    class ArrayDadosFuncionais extends AbstractStructArrayBase
    {
    /
    *
    • The dadosFuncionais
    • Meta information extracted from the WSDL
      • minOccurs: 0
      • nillable: true
    • @var \SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType\ArrayOfDadosFuncionais
      /
      public $dadosFuncionais;
      // ....
      /
      *
    • Returns the attribute name
    • @see AbstractStructArrayBase::getAttributeName()
    • @return string dadosFuncionais
      */
      public function getAttributeName():string
      {
      return 'dadosFuncionais';
      }

=============================================================
namespace SuppCore\SigepeBackend\Integracao\DadoPessoal\Models\ArrayType;

use WsdlToPhp\PackageBase\AbstractStructArrayBase;

/**

  • This class stands for ArrayOfDadosFuncionais ArrayType
  • @subpackage Arrays
    */
    class ArrayOfDadosFuncionais extends AbstractStructArrayBase
    {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code you pasted seems incomplete. Normally, the constructor, __construct, has one argument which is typed as an array with an array as default value:

public function __construct(array $dadosFuncionais = array())
    {
        $this
            ->setDadosFuncionais($dadosFuncionais);
    }

This initialize the property as an array which allows to right away loop on the object using foreach.

To loop through the items using foreach (or for in twig), until PackageBase:5.0, you have to first call the $instance->initInternArray(); method. In my case, it does not throw an exception.

Please paste the whole code using gist if necessary

@maurobn
Copy link
Contributor Author

maurobn commented Apr 14, 2021 via email

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants