Skip to content

Commit

Permalink
fix some errors finded by code inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalii Akmashev committed Aug 8, 2019
1 parent 974139e commit db81188
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 34 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"keywords": ["php", "fias"],
"license": "MIT",
"require": {
"ext-soap": "*",
"ext-libxml": "*",
"ext-xmlreader": "*",
"php": ">=7.2",
"symfony/yaml": "^4.2",
"symfony/serializer": "^4.2",
Expand Down
2 changes: 1 addition & 1 deletion src/Downloader/CurlDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CurlDownloader implements Downloader
*/
public function download(string $url, SplFileInfo $localFile): void
{
if (!preg_match('#https?\://.+\.[^\.]+.*#', $url)) {
if (!preg_match('#https?://.+\.[^.]+.*#', $url)) {
throw new InvalidArgumentException("Wrong url format: {$url}");
}

Expand Down
2 changes: 1 addition & 1 deletion src/EntityDescriptor/BaseEntityDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function getField(string $name): EntityField

if (!$return) {
throw new InvalidArgumentException(
"EntityDescriptor doesn't have fild with name '{$name}'."
"EntityDescriptor doesn't have field with name '{$name}'."
);
}

Expand Down
27 changes: 19 additions & 8 deletions src/EntityManager/BaseEntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Liquetsoft\Fias\Component\EntityDescriptor\EntityDescriptor;
use Liquetsoft\Fias\Component\EntityRegistry\EntityRegistry;
use InvalidArgumentException;
use Liquetsoft\Fias\Component\Exception\EntityRegistryException;

/**
* Объект, который содержит соответствия между сущностями ФИАС и их реализациями
Expand Down Expand Up @@ -48,7 +49,9 @@ public function __construct(EntityRegistry $registry, array $bindings)
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws EntityRegistryException
*/
public function getDescriptorByEntityName(string $entityName): ?EntityDescriptor
{
Expand All @@ -73,7 +76,9 @@ public function getClassByDescriptor(EntityDescriptor $descriptor): ?string
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws EntityRegistryException
*/
public function getDescriptorByInsertFile(string $insertFileName): ?EntityDescriptor
{
Expand All @@ -91,7 +96,9 @@ public function getDescriptorByInsertFile(string $insertFileName): ?EntityDescri
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws EntityRegistryException
*/
public function getDescriptorByDeleteFile(string $insertFileName): ?EntityDescriptor
{
Expand All @@ -109,16 +116,18 @@ public function getDescriptorByDeleteFile(string $insertFileName): ?EntityDescri
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws EntityRegistryException
*/
public function getDescriptorByClass(string $className): ?EntityDescriptor
{
$normalizedClassName = $this->normalizeClassName($className);
$entityName = null;

foreach ($this->bindings as $bindedEntity => $bindedClass) {
if ($normalizedClassName === $bindedClass) {
$entityName = $bindedEntity;
foreach ($this->bindings as $bindEntity => $bindClass) {
if ($normalizedClassName === $bindClass) {
$entityName = $bindEntity;
break;
}
}
Expand All @@ -127,7 +136,9 @@ public function getDescriptorByClass(string $className): ?EntityDescriptor
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws EntityRegistryException
*/
public function getDescriptorByObject($object): ?EntityDescriptor
{
Expand Down
2 changes: 1 addition & 1 deletion src/FiasInformer/InformerResponseBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function getVersion(): int
*/
public function setUrl(string $url): InformerResponse
{
if (!preg_match('#https?\://.+\.[^\.]+.*#', $url)) {
if (!preg_match('#https?://.+\.[^.]+.*#', $url)) {
throw new InvalidArgumentException("Wrong url format: {$url}");
}

Expand Down
4 changes: 2 additions & 2 deletions src/FiasInformer/SoapFiasInformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(SoapClient $soapClient)
*/
public function getCompleteInfo(): InformerResponse
{
$response = $this->soapClient->GetLastDownloadFileInfo();
$response = $this->soapClient->__call('GetLastDownloadFileInfo', []);

$res = new InformerResponseBase;
$res->setVersion((int) $response->GetLastDownloadFileInfoResult->VersionId);
Expand All @@ -44,7 +44,7 @@ public function getCompleteInfo(): InformerResponse
*/
public function getDeltaInfo(int $version): InformerResponse
{
$response = $this->soapClient->GetAllDownloadFileInfo();
$response = $this->soapClient->__call('GetAllDownloadFileInfo', []);
$versions = $this->sortResponseByVersion($response->GetAllDownloadFileInfoResult->DownloadFileInfo);

$res = new InformerResponseBase;
Expand Down
7 changes: 6 additions & 1 deletion src/Pipeline/Pipe/ArrayPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Liquetsoft\Fias\Component\Pipeline\Pipe;

use Exception;
use Liquetsoft\Fias\Component\Pipeline\State\State;
use Liquetsoft\Fias\Component\Pipeline\Task\Task;
use Liquetsoft\Fias\Component\Exception\PipeException;
Expand Down Expand Up @@ -48,7 +49,9 @@ public function __construct(iterable $tasks, ?Task $cleanupTask = null)
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws Exception
*/
public function run(State $state): Pipe
{
Expand All @@ -75,6 +78,8 @@ public function run(State $state): Pipe
* Обработка завершения задачи.
*
* @param State $state
*
* @throws Exception
*/
protected function cleanup(State $state): void
{
Expand Down
6 changes: 3 additions & 3 deletions src/Pipeline/Task/CleanupTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function run(State $state): void

$toRemove = array_diff($toRemove, [null]);

foreach ($toRemove as $fileinfo) {
if ($fileinfo instanceof SplFileInfo) {
FileSystemHelper::remove($fileinfo);
foreach ($toRemove as $fileInfo) {
if ($fileInfo instanceof SplFileInfo) {
FileSystemHelper::remove($fileInfo);
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/Pipeline/Task/DataAbstractTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Liquetsoft\Fias\Component\Pipeline\Task;

use Liquetsoft\Fias\Component\EntityManager\EntityManager;
use Liquetsoft\Fias\Component\Exception\StorageException;
use Liquetsoft\Fias\Component\Exception\XmlException;
use Liquetsoft\Fias\Component\XmlReader\XmlReader;
use Liquetsoft\Fias\Component\Storage\Storage;
use Liquetsoft\Fias\Component\Pipeline\State\State;
Expand Down Expand Up @@ -98,6 +100,10 @@ public function run(State $state): void
* Обрабатывает указанный файл.
*
* @param SplFileInfo $fileInfo
*
* @throws TaskException
* @throws StorageException
* @throws XmlException
*/
protected function processFile(SplFileInfo $fileInfo): void
{
Expand All @@ -116,6 +122,10 @@ protected function processFile(SplFileInfo $fileInfo): void
* @param SplFileInfo $fileInfo
* @param string $xpath
* @param string $entityClass
*
* @throws TaskException
* @throws StorageException
* @throws XmlException
*/
protected function processDataFromFile(SplFileInfo $fileInfo, string $xpath, string $entityClass): void
{
Expand Down Expand Up @@ -147,7 +157,7 @@ protected function deserializeXmlStringToObject(string $xml, string $entityClass
try {
$entity = $this->serializer->deserialize($xml, $entityClass, 'xml');
} catch (Throwable $e) {
$message = "Deserialization error while deserializing '{$xml}' string to object with '{$entityClass}' class.";
$message = "Deserialization error while deserialization of '{$xml}' string to object with '{$entityClass}' class.";
throw new TaskException($message, 0, $e);
}

Expand Down
5 changes: 4 additions & 1 deletion src/Pipeline/Task/DataDeleteTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Liquetsoft\Fias\Component\Pipeline\Task;

use Liquetsoft\Fias\Component\EntityDescriptor\EntityDescriptor;
use Liquetsoft\Fias\Component\Exception\StorageException;
use SplFileInfo;

/**
Expand All @@ -21,7 +22,9 @@ protected function getDescriptorForFile(SplFileInfo $fileInfo): ?EntityDescripto
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws StorageException
*/
protected function processItem(object $item): void
{
Expand Down
5 changes: 4 additions & 1 deletion src/Pipeline/Task/DataInsertTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Liquetsoft\Fias\Component\Pipeline\Task;

use Liquetsoft\Fias\Component\EntityDescriptor\EntityDescriptor;
use Liquetsoft\Fias\Component\Exception\StorageException;
use SplFileInfo;

/**
Expand All @@ -21,7 +22,9 @@ protected function getDescriptorForFile(SplFileInfo $fileInfo): ?EntityDescripto
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws StorageException
*/
protected function processItem(object $item): void
{
Expand Down
5 changes: 4 additions & 1 deletion src/Pipeline/Task/DataUpsertTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Liquetsoft\Fias\Component\Pipeline\Task;

use Liquetsoft\Fias\Component\EntityDescriptor\EntityDescriptor;
use Liquetsoft\Fias\Component\Exception\StorageException;
use SplFileInfo;

/**
Expand All @@ -22,7 +23,9 @@ protected function getDescriptorForFile(SplFileInfo $fileInfo): ?EntityDescripto
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws StorageException
*/
protected function processItem(object $item): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pipeline/Task/UnpackTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UnpackTask implements Task
protected $unpacker;

/**
* @param Unpacker $downloader
* @param Unpacker $unpacker
*/
public function __construct(Unpacker $unpacker)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Unpacker/RarUnpacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function unpack(SplFileInfo $source, SplFileInfo $destination): void

try {
$archive = RarArchive::open($source->getPathname());
$this->extractArciveTo($archive, $destination);
$this->extractArchiveTo($archive, $destination);
} catch (Throwable $e) {
$message = "Can't extract '" . $source->getPathname() . "' to '" . $destination->getPathname() . "'.";
throw new UnpackerException($message, 0, $e);
Expand All @@ -55,7 +55,7 @@ public function unpack(SplFileInfo $source, SplFileInfo $destination): void
*
* @psalm-suppress TooFewArguments
*/
protected function extractArciveTo(RarArchive $archive, SplFileInfo $destination): void
protected function extractArchiveTo(RarArchive $archive, SplFileInfo $destination): void
{
$entries = $archive->getEntries();
$path = $destination->getPathname();
Expand Down
20 changes: 14 additions & 6 deletions src/XmlReader/BaseXmlReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ public function close(): void
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws XmlException
*/
public function rewind()
{
Expand All @@ -98,7 +100,9 @@ public function rewind()
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws XmlException
*/
public function current()
{
Expand All @@ -119,7 +123,9 @@ public function key()
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws XmlException
*/
public function next()
{
Expand All @@ -129,7 +135,9 @@ public function next()
}

/**
* @inheritdoc
* {@inheritdoc}
*
* @throws XmlException
*/
public function valid()
{
Expand Down Expand Up @@ -261,13 +269,13 @@ protected function seekXmlPath(): bool
protected function resetReader(): PhpXmlReader
{
if (!$this->file || !$this->xpath) {
throw new XmlException("File doesn't open");
throw new XmlException("File doesn't open.");
}

$this->unsetReader();
$this->reader = new PhpXmlReader;

if ($this->reader->open($this->file->getPathname()) === false) {
if ($this->reader->open($this->file->getPathname(), 'UTF-8', LIBXML_COMPACT) === false) {
throw new RuntimeException(
"Can't open file '" . $this->file->getPathname() . "' for reading."
);
Expand Down
10 changes: 6 additions & 4 deletions tests/src/FiasInformer/SoapFiasInformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public function testGetCompleteInfo()
$soapResponse->GetLastDownloadFileInfoResult->VersionId = $this->createFakeData()->randomNumber;

$soapClient = $this->getMockBuilder(SoapClient::class)
->setMethods(['GetLastDownloadFileInfo'])
->disableOriginalConstructor()
->getMock();
$soapClient->method('GetLastDownloadFileInfo')->will($this->returnValue($soapResponse));
$soapClient->method('__call')
->with($this->identicalTo('GetLastDownloadFileInfo'))
->will($this->returnValue($soapResponse));

$service = new SoapFiasInformer($soapClient);
$result = $service->getCompleteInfo();
Expand Down Expand Up @@ -69,10 +70,11 @@ public function testGetDeltaInfo()
shuffle($soapResponse->GetAllDownloadFileInfoResult->DownloadFileInfo);

$soapClient = $this->getMockBuilder(SoapClient::class)
->setMethods(['GetAllDownloadFileInfo'])
->disableOriginalConstructor()
->getMock();
$soapClient->method('GetAllDownloadFileInfo')->will($this->returnValue($soapResponse));
$soapClient->method('__call')
->with($this->identicalTo('GetAllDownloadFileInfo'))
->will($this->returnValue($soapResponse));

$service = new SoapFiasInformer($soapClient);
$result = $service->getDeltaInfo($currentDelta);
Expand Down

0 comments on commit db81188

Please sign in to comment.