Skip to content

Commit

Permalink
Fix Issue #26 Strict Typing (#80)
Browse files Browse the repository at this point in the history
Added strict typing
  • Loading branch information
tolbon authored and janvernieuwe committed Nov 24, 2017
1 parent cc15a60 commit c5c2d6e
Show file tree
Hide file tree
Showing 79 changed files with 276 additions and 248 deletions.
10 changes: 5 additions & 5 deletions src/Phpro/SoapClient/Client.php
Expand Up @@ -10,7 +10,7 @@
use Phpro\SoapClient\Type\ResultInterface;
use Phpro\SoapClient\Type\ResultProviderInterface;
use SoapClient;
use SoapFault;

use SoapHeader;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

Expand Down Expand Up @@ -45,7 +45,7 @@ public function __construct(SoapClient $soapClient, EventDispatcherInterface $di
* @param SoapHeader|SoapHeader[] $soapHeaders
* @return $this
*/
public function applySoapHeaders($soapHeaders)
public function applySoapHeaders($soapHeaders): self
{
$this->soapClient->__setSoapHeaders($soapHeaders);
return $this;
Expand All @@ -56,7 +56,7 @@ public function applySoapHeaders($soapHeaders)
*
* @return array
*/
public function debugLastSoapRequest()
public function debugLastSoapRequest(): array
{
return [
'request' => [
Expand All @@ -73,7 +73,7 @@ public function debugLastSoapRequest()
/**
* @param string $location
*/
public function changeSoapLocation($location)
public function changeSoapLocation(string $location)
{
$this->soapClient->__setLocation($location);
}
Expand All @@ -85,7 +85,7 @@ public function changeSoapLocation($location)
* @return ResultInterface
* @throws SoapException
*/
protected function call($method, RequestInterface $request)
protected function call(string $method, RequestInterface $request): ResultInterface
{
$requestEvent = new Event\RequestEvent($this, $method, $request);
$this->dispatcher->dispatch(Events::REQUEST, $requestEvent);
Expand Down
4 changes: 2 additions & 2 deletions src/Phpro/SoapClient/ClientBuilder.php
Expand Up @@ -89,7 +89,7 @@ class ClientBuilder
* @param string $wsdl
* @param array $soapOptions
*/
public function __construct(ClientFactoryInterface $clientFactory, $wsdl, array $soapOptions = [])
public function __construct(ClientFactoryInterface $clientFactory, string $wsdl, array $soapOptions = [])
{
$this->classMaps = new ClassMapCollection();
$this->converters = new TypeConverterCollection();
Expand Down Expand Up @@ -190,7 +190,7 @@ public function addMiddleware(MiddlewareInterface $middleware)
* @return ClientInterface
* @throws \Phpro\SoapClient\Exception\InvalidArgumentException
*/
public function build()
public function build(): ClientInterface
{
$soapClientFactory = new SoapClientFactory($this->classMaps, $this->converters);
$soapClient = $soapClientFactory->factory($this->wsdlProvider->provide($this->wsdl), $this->soapOptions);
Expand Down
7 changes: 4 additions & 3 deletions src/Phpro/SoapClient/ClientFactory.php
Expand Up @@ -2,8 +2,8 @@

namespace Phpro\SoapClient;

use SoapClient;
use ReflectionClass;
use SoapClient;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand All @@ -22,20 +22,21 @@ class ClientFactory implements ClientFactoryInterface
/**
* @param string $className
*/
public function __construct($className)
public function __construct(string $className)
{
$this->className = $className;
}

/**
* @param SoapClient $soapClient
* @param SoapClient $soapClient
* @param EventDispatcherInterface $dispatcher
*
* @return object
*/
public function factory(SoapClient $soapClient, EventDispatcherInterface $dispatcher)
{
$rc = new ReflectionClass($this->className);

return $rc->newInstance($soapClient, $dispatcher);
}
}
2 changes: 1 addition & 1 deletion src/Phpro/SoapClient/ClientFactoryInterface.php
Expand Up @@ -14,7 +14,7 @@ interface ClientFactoryInterface
{

/**
* @param SoapClient $soapClient
* @param SoapClient $soapClient
* @param EventDispatcherInterface $dispatcher
*
* @return ClientInterface
Expand Down
Expand Up @@ -18,7 +18,7 @@ interface AssemblerInterface
*
* @return bool
*/
public function canAssemble(ContextInterface $context);
public function canAssemble(ContextInterface $context): bool;

/**
* Assembles pieces of code.
Expand Down
Expand Up @@ -21,7 +21,7 @@ class ClassMapAssembler implements AssemblerInterface
*
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof ClassMapContext;
}
Expand Down Expand Up @@ -56,7 +56,7 @@ public function assemble(ContextInterface $context)
*
* @return string
*/
private function assembleClassMap(TypeMap $typeMap, $linefeed, $indentation)
private function assembleClassMap(TypeMap $typeMap, string $linefeed, string $indentation): string
{
$classMap = [];
foreach ($typeMap->getTypes() as $type) {
Expand All @@ -77,7 +77,7 @@ private function assembleClassMap(TypeMap $typeMap, $linefeed, $indentation)
*
* @return string
*/
private function assembleClassMapCollection($classMap, $linefeed)
private function assembleClassMapCollection(string $classMap, string $linefeed): string
{
$code = [
'new ClassMapCollection([',
Expand Down
Expand Up @@ -19,17 +19,18 @@ class ClientMethodAssembler implements AssemblerInterface
/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof ClientMethodContext;
}

/**
* @param ContextInterface|ClientMethodContext $context
*
* @return bool
* @throws AssemblerException
*/
public function assemble(ContextInterface $context)
public function assemble(ContextInterface $context): bool
{
$class = $context->getClass();
$class->setExtendedClass(Client::class);
Expand All @@ -50,12 +51,14 @@ public function assemble(ContextInterface $context)
$param->getName()
),
// TODO: Use normalizer once https://github.com/phpro/soap-client/pull/61 is merged
'returntype' => '\\'.$method->getParameterNamespace().'\\'.$method->getReturnType(),
'returntype' => '\\'.$method->getParameterNamespace().'\\'.$method->getReturnType(),
]
)
);
} catch (\Exception $e) {
throw AssemblerException::fromException($e);
}

return true;
}
}
Expand Up @@ -21,7 +21,7 @@ class ConstructorAssembler implements AssemblerInterface
*
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down Expand Up @@ -49,7 +49,7 @@ public function assemble(ContextInterface $context)
* @return MethodGenerator
* @throws \Zend\Code\Generator\Exception\InvalidArgumentException
*/
private function assembleConstructor(Type $type)
private function assembleConstructor(Type $type): MethodGenerator
{
$body = [];
$constructor = MethodGenerator::fromArray([
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function __construct(string $extendedClassName)
*
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down
Expand Up @@ -18,7 +18,7 @@ class FinalClassAssembler implements AssemblerInterface
*
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down
Expand Up @@ -36,7 +36,7 @@ public function __construct(FluentSetterAssemblerOptions $options)
/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context) : bool
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof PropertyContext;
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ class ImmutableSetterAssembler implements AssemblerInterface
*
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof PropertyContext;
}
Expand Down
Expand Up @@ -34,7 +34,7 @@ public function __construct($interfaceName)
*
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext || $context instanceof PropertyContext;
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ class IteratorAssembler implements AssemblerInterface
*
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down Expand Up @@ -58,7 +58,7 @@ public function assemble(ContextInterface $context)
*
* @throws \Zend\Code\Generator\Exception\InvalidArgumentException
*/
private function implementGetIterator($class, $firstProperty)
private function implementGetIterator(ClassGenerator $class, Property $firstProperty)
{
$methodName = 'getIterator';
$class->removeMethod($methodName);
Expand Down
Expand Up @@ -21,7 +21,7 @@ class JsonSerializableAssembler implements AssemblerInterface
/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down
Expand Up @@ -24,15 +24,15 @@ class PropertyAssembler implements AssemblerInterface
* PropertyAssembler constructor.
* @param string $visibility
*/
public function __construct($visibility = PropertyGenerator::VISIBILITY_PRIVATE)
public function __construct(string $visibility = PropertyGenerator::VISIBILITY_PRIVATE)
{
$this->visibility = $visibility;
}

/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof PropertyContext;
}
Expand Down
Expand Up @@ -17,7 +17,7 @@ class RequestAssembler implements AssemblerInterface
/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down
Expand Up @@ -17,7 +17,7 @@ class ResultAssembler implements AssemblerInterface
/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public function __construct($wrapperClass = null)
/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext;
}
Expand Down Expand Up @@ -107,7 +107,7 @@ private function implementGetResult(ContextInterface $context, ClassGenerator $c
*
* @return string
*/
private function generateGetResultBody(Property $property)
private function generateGetResultBody(Property $property): string
{
if ($this->wrapperClass === null) {
return sprintf('return $this->%s;', $property->getName());
Expand All @@ -125,7 +125,7 @@ private function generateGetResultBody(Property $property)
*
* @return string
*/
private function generateGetResultReturnTag(Property $property)
private function generateGetResultReturnTag(Property $property): string
{
if ($this->wrapperClass === null) {
return $property->getType() . '|' . Normalizer::getClassNameFromFQN(ResultInterface::class);
Expand Down
Expand Up @@ -20,7 +20,7 @@ class SetterAssembler implements AssemblerInterface
/**
* {@inheritdoc}
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof PropertyContext;
}
Expand Down
Expand Up @@ -26,10 +26,10 @@ class TraitAssembler implements AssemblerInterface

/**
* TraitAssembler constructor.
* @param $traitName
* @param $traitAlias
* @param string $traitName
* @param string $traitAlias
*/
public function __construct($traitName, $traitAlias = null)
public function __construct(string $traitName, $traitAlias = null)
{
$this->traitName = Normalizer::normalizeNamespace($traitName);
$this->traitAlias = $traitAlias;
Expand All @@ -39,7 +39,7 @@ public function __construct($traitName, $traitAlias = null)
* @param ContextInterface $context
* @return bool
*/
public function canAssemble(ContextInterface $context)
public function canAssemble(ContextInterface $context): bool
{
return $context instanceof TypeContext || $context instanceof PropertyContext;
}
Expand Down

0 comments on commit c5c2d6e

Please sign in to comment.