diff --git a/.travis.yml b/.travis.yml index 9f25a07..c87cda5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,4 +16,5 @@ install: script: - bin/phpspec run -f pretty + - bin/phpstan analyze --level 5 - bin/behat --no-snippets --verbose diff --git a/Behat/Context/CommandContext.php b/Behat/Context/CommandContext.php index f1b08ac..773af53 100644 --- a/Behat/Context/CommandContext.php +++ b/Behat/Context/CommandContext.php @@ -43,12 +43,7 @@ public function __construct($fixturesPath) $this->fixturesPath = $fixturesPath; } - /** - * Sets Kernel instance. - * - * @param KernelInterface $kernel HttpKernel instance - */ - public function setKernel(KernelInterface $kernel) + public function setKernel(KernelInterface $kernel): void { $this->kernel = $kernel; } @@ -56,29 +51,31 @@ public function setKernel(KernelInterface $kernel) /** * @When /^I successfully run console command "([^"]*)"$/ */ - public function iRunConsoleCommand($command) + public function iRunConsoleCommand(string $command): void { $application = new Application($this->kernel); $tester = new ApplicationTester($application); - expect($tester->run($command))->toBe(0); + expect($tester->run([$command]))->toBe(0); $this->lastCommandOutput = $tester->getDisplay(true); } /** * @When /^I run console command "([^"]*)" with argument "--([^"]*)=([^"]*)"$/ */ - public function iRunConsoleCommandWithArgument($command, $argument, $value = 1) + public function iRunConsoleCommandWithArgument(string $command, string $argument, string $value = ''): void { $application = new Application($this->kernel); $tester = new ApplicationTester($application); $value = $this->prepareValue($argument, $value); - $this->lastCommandExitCode = $tester->run(array( + $this->lastCommandExitCode = $tester->run( + [ $command, $argument => $value - )); + ] + ); $this->lastCommandOutput = $tester->getDisplay(true); } @@ -86,15 +83,15 @@ public function iRunConsoleCommandWithArgument($command, $argument, $value = 1) /** * @When /^I unsuccessfully run console command "([^"]*)" with argument "--([^"]*)=([^"]*)"$/ */ - public function iUnsuccessfullyRunConsoleCommandWithArgument($command, $argument, $value) + public function iUnsuccessfullyRunConsoleCommandWithArgument(string $command, string $argument, string $value): void { $application = new Application($this->kernel); $tester = new ApplicationTester($application); - expect($tester->run(array( + expect($tester->run([ $command, $argument => $value - )))->toBe(1); + ]))->toBe(1); $this->lastCommandOutput = $tester->getDisplay(true); } @@ -103,17 +100,17 @@ public function iUnsuccessfullyRunConsoleCommandWithArgument($command, $argument /** * @When /^I successfully run console command "([^"]*)" with argument "--([^"]*)=([^"]*)"$/ */ - public function iSuccessfullyRunConsoleCommandWithArgument($command, $argument, $value) + public function iSuccessfullyRunConsoleCommandWithArgument(string $command, string $argument, string $value): void { $application = new Application($this->kernel); $tester = new ApplicationTester($application); $value = $this->prepareValue($argument, $value); - expect($tester->run(array( + expect($tester->run([ $command, $argument => $value - )))->toBe(0); + ]))->toBe(0); $this->lastCommandOutput = $tester->getDisplay(true); } @@ -122,30 +119,20 @@ public function iSuccessfullyRunConsoleCommandWithArgument($command, $argument, * @Then /^I should see "([^"]*)" console output$/ * @Given /^I should see "([^"]*)" output at console$/ */ - public function iShouldSeeOutputAtConsole($consoleOutput) + public function iShouldSeeOutputAtConsole(string $consoleOutput): void { expect(trim($this->getLastCommandOutput()))->toBe($consoleOutput); } - /** - * @return mixed - */ - public function getLastCommandOutput() + public function getLastCommandOutput(): string { return $this->lastCommandOutput; } - /** - * @param $argument - * @param $value - * @return string - */ - public function prepareValue($argument, $value) + public function prepareValue(string $argument, string $value): string { - switch ($argument) { - case 'file': - $value = $this->kernel->getRootDir() . DIRECTORY_SEPARATOR . $value; - break; + if ($argument === 'file') { + return $this->kernel->getRootDir() . DIRECTORY_SEPARATOR . $value; } return $value; diff --git a/Behat/Context/Console/ApplicationTester.php b/Behat/Context/Console/ApplicationTester.php index c495da8..c500b74 100644 --- a/Behat/Context/Console/ApplicationTester.php +++ b/Behat/Context/Console/ApplicationTester.php @@ -14,7 +14,8 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Input\StringInput; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\StreamOutput; class ApplicationTester @@ -25,7 +26,7 @@ class ApplicationTester private $application; /** - * @var StringInput $input + * @var ArrayInput $input */ private $input; @@ -39,42 +40,25 @@ class ApplicationTester */ private $inputStream; - /** - * @param Application $application - */ public function __construct(Application $application) { $this->application = $application; } - /** - * @param array $input - * - * @return integer - */ - public function run($input = array()) + public function run(array $input = []): int { - $this->input = new ArrayInput((array) $input); + $this->input = new ArrayInput($input); $this->input->setInteractive(false); - $this->output = new StreamOutput(fopen('php://memory', 'r+', false)); - - $inputStream = $this->getInputStream(); - rewind($inputStream); + $this->output = new StreamOutput(fopen('php://memory', 'rb+', false)); - /** @var QuestionHelper $questionHelper */ - $questionHelper = $this->application->getHelperSet()->get('question'); - $questionHelper->setInputStream($inputStream); + $this->initializeInputStream(); + rewind($this->inputStream); return $this->application->doRun($this->input, $this->output); } - /** - * @param boolean - * - * @return string - */ - public function getDisplay($normalize = false) + public function getDisplay(bool $normalize = false): string { rewind($this->output->getStream()); @@ -87,39 +71,27 @@ public function getDisplay($normalize = false) return $display; } - /** - * @return \Symfony\Component\Console\Input\InputInterface - */ - public function getInput() + public function getInput(): InputInterface { return $this->input; } - /** - * @return \Symfony\Component\Console\Output\OutputInterface - */ - public function getOutput() + public function getOutput(): OutputInterface { return $this->output; } - /** - * @param string $input - */ - public function putToInputStream($input) + public function putToInputStream(string $input): void { - fputs($this->getInputStream(), $input); + $this->initializeInputStream(); + + fwrite($this->inputStream, $input); } - /** - * @return resource - */ - private function getInputStream() + private function initializeInputStream(): void { if (null === $this->inputStream) { $this->inputStream = fopen('php://memory', 'r+', false); } - - return $this->inputStream; } } diff --git a/Behat/Context/DataContext.php b/Behat/Context/DataContext.php index 93c45b4..fa087cc 100644 --- a/Behat/Context/DataContext.php +++ b/Behat/Context/DataContext.php @@ -11,7 +11,6 @@ namespace FSi\Bundle\TerytDatabaseBundle\Behat\Context; -use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Gherkin\Node\TableNode; use Behat\Symfony2Extension\Context\KernelAwareContext; use FSi\Bundle\TerytDatabaseBundle\Entity\Community; @@ -35,12 +34,7 @@ class DataContext implements KernelAwareContext */ protected $lastCommandOutput; - /** - * Sets Kernel instance. - * - * @param KernelInterface $kernel HttpKernel instance - */ - public function setKernel(KernelInterface $kernel) + public function setKernel(KernelInterface $kernel): void { $this->kernel = $kernel; } @@ -48,259 +42,235 @@ public function setKernel(KernelInterface $kernel) /** * @Given /^following province was already imported$/ */ - public function followingProvinceWasAlreadyImported(TableNode $table) + public function followingProvinceWasAlreadyImported(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { - $this->createProvince($row['Code'], $row['Name']); + $this->createProvince((int) $row['Code'], $row['Name']); } } /** * @Given /^following district was already imported$/ */ - public function followingDistrictWasAlreadyImported(TableNode $table) + public function followingDistrictWasAlreadyImported(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { - $this->createDistrict($row['Code'], $row['Name'], $this->findProvinceByName($row['Province'])); + $this->createDistrict((int) $row['Code'], $row['Name'], $this->findProvinceByName($row['Province'])); } } /** * @Given /^following places was already imported$/ */ - public function followingPlacesWasAlreadyImported(TableNode $table) + public function followingPlacesWasAlreadyImported(TableNode $table): void { $this->createPlaceType(1, 'fake'); $tableHash = $table->getHash(); foreach ($tableHash as $row) { - $this->createPlace($row['Identity'], $row['Name'], 'fake', $row['Community']); + $this->createPlace((int) $row['Identity'], $row['Name'], 'fake', $row['Community']); } } /** * @Given /^following community was already imported$/ */ - public function followingCommunityWasAlreadyImported(TableNode $table) + public function followingCommunityWasAlreadyImported(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { - $this->createCommunity($row['Code'], $row['Name'], $row['Community type'], $row['District']); + $this->createCommunity((int) $row['Code'], $row['Name'], $row['Community type'], $row['District']); } } /** * @Then /^following place should exist in database$/ */ - public function followingPlaceShouldExistInDatabase(TableNode $table) + public function followingPlaceShouldExistInDatabase(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { - $this->createPlace($row['Identity'], $row['Name'], $row['Place type'], $row['Community']); + $this->createPlace((int) $row['Identity'], $row['Name'], $row['Place type'], $row['Community']); } } /** * @Then /^following places dictionary exist in database$/ */ - public function followingPlacesDictionaryExistInDatabase(TableNode $table) + public function followingPlacesDictionaryExistInDatabase(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { - $this->createPlaceType($row['Type'], $row['Name']); + $this->createPlaceType((int) $row['Type'], $row['Name']); } } /** * @Given /^following streets was already imported$/ */ - public function followingStreetsWasAlreadyImported(TableNode $table) + public function followingStreetsWasAlreadyImported(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { - $this->createStreet($row['Identity'], $row['Type'], $row['Name'], $row['Additional name'], $row['Place']); + $this->createStreet( + (int) $row['Identity'], + $row['Type'], + $row['Name'], + $row['Additional name'] ?: null, + $row['Place'] + ); } } /** * @Given /^there is a community in database with code "([^"]*)" and name "([^"]*)" in district "([^"]*)"$/ */ - public function thereIsACommunityInDatabaseWithCodeAndName($code, $name, $district) + public function thereIsACommunityInDatabaseWithCodeAndName(string $code, string $name, string $district): void { $this->createCommunityType(1, 'fake'); - $this->createCommunity($code, $name, 'fake', $district); + $this->createCommunity((int) $code, $name, 'fake', $district); } /** * @Given /^there is a place type with type "([^"]*)" and name "([^"]*)"$/ */ - public function thereIsAPlaceTypeWithTypeAndName($type, $name) + public function thereIsAPlaceTypeWithTypeAndName(string $type, string $name): void { - $placeType = new PlaceType($type); - $placeType->setName($name); + $placeType = new PlaceType((int) $type, $name); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($placeType); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - /** - * @param $code - * @param $name - * @param $typeName - * @param $districtName - * @internal param $row - */ - protected function createCommunity($code, $name, $typeName, $districtName) + protected function createCommunity(int $code, string $name, string $typeName, string $districtName): void { - $community = new Community($code); - $community->setName($name) - ->setType($this->findCommunityTypeByName($typeName)) - ->setDistrict($this->findDistrictByName($districtName)); + $community = new Community( + $this->findDistrictByName($districtName), + $code, + $name, + $this->findCommunityTypeByName($typeName) + ); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($community); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - protected function createCommunityType($type, $name) + protected function createCommunityType(int $type, string $name): void { - $communityType = new CommunityType($type); - $communityType->setName($name); + $communityType = new CommunityType($type, $name); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($communityType); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - protected function createPlace($id, $name, $typeName = null, $communityName = null) + protected function createPlace(int $id, string $name, string $typeName, string $communityName): void { - $place = new Place($id); - $place->setName($name); + $type = $this->findPlaceTypeByName($typeName); + $community = $this->findCommunityByName($communityName); - if (isset($typeName)) { - $place->setType($this->findPlaceTypeByName($typeName)); - } - - if (isset($communityName)) { - $place->setCommunity($this->findCommunityByName($communityName)); - } + $place = new Place($id, $name, $type, $community); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($place); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - protected function createPlaceType($type, $name) + protected function createPlaceType(int $type, string $name): void { - $placeType = new PlaceType($type); - $placeType->setName($name); + $placeType = new PlaceType($type, $name); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($placeType); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - - protected function createProvince($code, $name) + protected function createProvince(int $code, string $name): void { - $provinceEntity = new Province($code); - $provinceEntity->setName($name); + $provinceEntity = new Province($code, $name); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($provinceEntity); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - - protected function createDistrict($code, $name, Province $province) + protected function createDistrict(int $code, string $name, Province $province): void { - $communityEntity = new District($code); - $communityEntity->setName($name) - ->setProvince($province); + $communityEntity = new District($province, $code, $name); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($communityEntity); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - /** - * @param $id - * @param $type - * @param $name - * @param $additionalName - * @param $placeName - * @internal param $row - */ - private function createStreet($id, $type, $name, $additionalName, $placeName) + private function createStreet(int $id, string $type, string $name, ?string $additionalName, string $placeName): void { - $street = new Street($this->findPlaceByName($placeName), $id); - $street->setType($type) - ->setName($name) - ->setAdditionalName($additionalName); + $street = new Street($this->findPlaceByName($placeName), $id, $type, $additionalName, $name); $this->kernel->getContainer()->get('doctrine')->getManager()->persist($street); $this->kernel->getContainer()->get('doctrine')->getManager()->flush(); } - protected function findProvinceByName($name) + protected function findProvinceByName(string $name): ?Province { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:Province') + ->getRepository(Province::class) ->findOneByName($name); } - protected function findDistrictByName($name) + protected function findDistrictByName(string $name): ?District { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:District') + ->getRepository(District::class) ->findOneByName($name); } - protected function findCommunityByName($name) + protected function findCommunityByName(string $name): ?Community { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:Community') + ->getRepository(Community::class) ->findOneByName($name); } - protected function findCommunityTypeByName($name) + protected function findCommunityTypeByName(string $name): ?CommunityType { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:CommunityType') + ->getRepository(CommunityType::class) ->findOneByName($name); } - protected function findPlaceTypeByName($name) + protected function findPlaceTypeByName(string $name): ?PlaceType { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:PlaceType') + ->getRepository(PlaceType::class) ->findOneByName($name); } - protected function findPlaceByName($name) + protected function findPlaceByName(string $name): ?Place { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:Place') + ->getRepository(Place::class) ->findOneByName($name); } } diff --git a/Behat/Context/DownloadTerytCommandContext.php b/Behat/Context/DownloadTerytCommandContext.php index d192ce5..b79a1b6 100644 --- a/Behat/Context/DownloadTerytCommandContext.php +++ b/Behat/Context/DownloadTerytCommandContext.php @@ -32,7 +32,7 @@ public function __construct($fixturesPath) $this->fixturesPath = $fixturesPath; } - public function setKernel(KernelInterface $kernel) + public function setKernel(KernelInterface $kernel): void { $this->kernel = $kernel; } @@ -40,7 +40,7 @@ public function setKernel(KernelInterface $kernel) /** * @Then /^"([^"]*)" file should be downloaded into "([^"]*)" folder$/ */ - public function fileShouldBeDownloadedIntoFolder($fileName, $targetFilesPath) + public function fileShouldBeDownloadedIntoFolder(string $fileName, string $targetFilesPath): void { $downloadPath = realpath( __DIR__ . '/../' . $targetFilesPath); $filePath = $downloadPath . '/' . $fileName; @@ -50,7 +50,7 @@ public function fileShouldBeDownloadedIntoFolder($fileName, $targetFilesPath) /** * @AfterScenario */ - public function afterScenario() + public function afterScenario(): void { $terytDownloadPath = $this->fixturesPath . '/Project/app/teryt'; if (!file_exists($terytDownloadPath)) { diff --git a/Behat/Context/ImportTerytCommandContext.php b/Behat/Context/ImportTerytCommandContext.php index b9aa6f3..637d990 100644 --- a/Behat/Context/ImportTerytCommandContext.php +++ b/Behat/Context/ImportTerytCommandContext.php @@ -14,7 +14,15 @@ use Behat\Gherkin\Node\PyStringNode; use Behat\Gherkin\Node\TableNode; use Behat\Symfony2Extension\Context\KernelAwareContext; +use Doctrine\ORM\EntityRepository; +use FSi\Bundle\TerytDatabaseBundle\Entity\District; +use FSi\Bundle\TerytDatabaseBundle\Entity\Place; +use FSi\Bundle\TerytDatabaseBundle\Entity\PlaceType; +use FSi\Bundle\TerytDatabaseBundle\Entity\Province; +use FSi\Bundle\TerytDatabaseBundle\Entity\Street; use Symfony\Component\HttpKernel\KernelInterface; +use FSi\Bundle\TerytDatabaseBundle\Entity\Community; +use FSi\Bundle\TerytDatabaseBundle\Entity\CommunityType; class ImportTerytCommandContext implements KernelAwareContext { @@ -28,17 +36,12 @@ class ImportTerytCommandContext implements KernelAwareContext */ protected $fixturesPath; - function __construct($fixturesPath) + public function __construct($fixturesPath) { $this->fixturesPath = $fixturesPath; } - /** - * Sets Kernel instance. - * - * @param KernelInterface $kernel HttpKernel instance - */ - public function setKernel(KernelInterface $kernel) + public function setKernel(KernelInterface $kernel): void { $this->kernel = $kernel; } @@ -46,14 +49,14 @@ public function setKernel(KernelInterface $kernel) /** * @Given /^"([^"]*)" file have following content:$/ */ - public function xmlFileHaveFollowingContent($fileName, PyStringNode $fileContent) + public function xmlFileHaveFollowingContent(string $fileName, PyStringNode $fileContent): void { - $targetFolder = sprintf("%s/Project/app/teryt", $this->fixturesPath); - if (!file_exists($targetFolder)) { - mkdir($targetFolder); + $targetFolder = sprintf('%s/Project/app/teryt', $this->fixturesPath); + if (!file_exists($targetFolder) && !mkdir($targetFolder) && !is_dir($targetFolder)) { + throw new \RuntimeException(sprintf('Directory "%s" was not created', $targetFolder)); } - $filePath = sprintf("%s/%s", $targetFolder, $fileName); + $filePath = sprintf('%s/%s', $targetFolder, $fileName); file_put_contents($filePath, $fileContent->getRaw()); expect(file_exists($filePath))->toBe(true); } @@ -61,67 +64,63 @@ public function xmlFileHaveFollowingContent($fileName, PyStringNode $fileContent /** * @Given /^there are no provinces in database$/ */ - public function thereAreNoProvincesInDatabase() + public function thereAreNoProvincesInDatabase(): void { - expect($this->getProvinceRepository() - ->findAll())->toBe(array()); + expect($this->getProvinceRepository()->findAll())->toBe([]); } /** * @Given /^there are no districts in database$/ */ - public function thereAreNoDistrictsInDatabase() + public function thereAreNoDistrictsInDatabase(): void { - expect($this->getDistrictRepository() - ->findAll())->toBe(array()); + expect($this->getDistrictRepository()->findAll())->toBe([]); } /** * @Given /^there are no communities in database$/ */ - public function thereAreNoCommunitiesInDatabase() + public function thereAreNoCommunitiesInDatabase(): void { - expect($this->getCommunityRepository() - ->findAll())->toBe(array()); + expect($this->getCommunityRepository()->findAll())->toBe([]); } /** * @Given /^places dictionary table in database is empty$/ */ - public function placesDictionaryTableInDatabaseIsEmpty() + public function placesDictionaryTableInDatabaseIsEmpty(): void { - expect($this->getPlaceTypeRepository() - ->findAll())->toBe(array()); + expect($this->getPlaceTypeRepository()->findAll())->toBe([]); } /** * @Given /^places table in database is empty$/ */ - public function placesTableInDatabaseIsEmpty() + public function placesTableInDatabaseIsEmpty(): void { - expect($this->getPlaceRepository() - ->findAll())->toBe(array()); + expect($this->getPlaceRepository()->findAll())->toBe([]); } /** * @Given /^there are no streets in database$/ */ - public function thereAreNoStreetsInDatabase() + public function thereAreNoStreetsInDatabase(): void { expect($this->getStreetRepository() - ->findAll())->toBe(array()); + ->findAll())->toBe([]); } /** * @Then /^following province should exist in database$/ */ - public function followingProvinceShouldExistInDatabase(TableNode $table) + public function followingProvinceShouldExistInDatabase(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { + /** @var Province|null $entity */ $entity = $this->getProvinceRepository()->findOneByCode($row['Code']); - expect($entity)->toBeAnInstanceOf('FSi\Bundle\TerytDatabaseBundle\Entity\Province'); + expect($entity)->toBeAnInstanceOf(Province::class); expect($entity->getName())->toBe($row['Name']); } } @@ -129,13 +128,14 @@ public function followingProvinceShouldExistInDatabase(TableNode $table) /** * @Then /^following district should exist in database$/ */ - public function followingDistrictShouldExistInDatabase(TableNode $table) + public function followingDistrictShouldExistInDatabase(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { + /** @var District|null $entity */ $entity = $this->getDistrictRepository()->findOneByCode($row['Code']); - expect($entity)->toBeAnInstanceOf('FSi\Bundle\TerytDatabaseBundle\Entity\District'); + expect($entity)->toBeAnInstanceOf(District::class); expect($entity->getName())->toBe($row['Name']); expect($entity->getProvince()->getName())->toBe($row['Province']); } @@ -144,13 +144,14 @@ public function followingDistrictShouldExistInDatabase(TableNode $table) /** * @Then /^following communities should exist in database$/ */ - public function followingCommunitiesShouldExistInDatabase(TableNode $table) + public function followingCommunitiesShouldExistInDatabase(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { + /** @var Community|null $entity */ $entity = $this->getCommunityRepository()->findOneByCode($row['Code']); - expect($entity)->toBeAnInstanceOf('FSi\Bundle\TerytDatabaseBundle\Entity\Community'); + expect($entity)->toBeAnInstanceOf(Community::class); expect($entity->getName())->toBe($row['Name']); expect($entity->getDistrict()->getName())->toBe($row['District']); expect($entity->getType()->getName())->toBe($row['Community type']); @@ -160,13 +161,14 @@ public function followingCommunitiesShouldExistInDatabase(TableNode $table) /** * @Then /^following community types should exist in database$/ */ - public function followingCommunityTypesShouldExistInDatabase(TableNode $table) + public function followingCommunityTypesShouldExistInDatabase(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { + /** @var CommunityType|null $entity */ $entity = $this->getCommunityTypeRepository()->findOneByType($row['Type']); - expect($entity)->toBeAnInstanceOf('FSi\Bundle\TerytDatabaseBundle\Entity\CommunityType'); + expect($entity)->toBeAnInstanceOf(CommunityType::class); expect($entity->getName())->toBe($row['Name']); } } @@ -174,13 +176,14 @@ public function followingCommunityTypesShouldExistInDatabase(TableNode $table) /** * @Then /^places dictionary table in database should have following records$/ */ - public function placesDictionaryTableInDatabaseShouldHaveFollowingRecords(TableNode $table) + public function placesDictionaryTableInDatabaseShouldHaveFollowingRecords(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { + /** @var PlaceType|null $entity */ $entity = $this->getPlaceTypeRepository()->findOneByType($row['Type']); - expect($entity)->toBeAnInstanceOf('FSi\Bundle\TerytDatabaseBundle\Entity\PlaceType'); + expect($entity)->toBeAnInstanceOf(PlaceType::class); expect($entity->getName())->toBe($row['Name']); } } @@ -188,13 +191,14 @@ public function placesDictionaryTableInDatabaseShouldHaveFollowingRecords(TableN /** * @Then /^places table in database should have following records$/ */ - public function placesTableInDatabaseShouldHaveFollowingRecords(TableNode $table) + public function placesTableInDatabaseShouldHaveFollowingRecords(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { + /** @var Place|null $entity */ $entity = $this->getPlaceRepository()->findOneById($row['Identity']); - expect($entity)->toBeAnInstanceOf('FSi\Bundle\TerytDatabaseBundle\Entity\Place'); + expect($entity)->toBeAnInstanceOf(Place::class); expect($entity->getName())->toBe($row['Name']); expect($entity->getType()->getName())->toBe($row['Place type']); expect($entity->getCommunity()->getName())->toBe($row['Community']); @@ -207,13 +211,13 @@ public function placesTableInDatabaseShouldHaveFollowingRecords(TableNode $table /** * @Then /^following streets should exist in database$/ */ - public function followingStreetsShouldExistInDatabase(TableNode $table) + public function followingStreetsShouldExistInDatabase(TableNode $table): void { $tableHash = $table->getHash(); foreach ($tableHash as $row) { $entity = $this->getStreetRepository()->findOneById($row['Identity']); - expect($entity)->toBeAnInstanceOf('FSi\Bundle\TerytDatabaseBundle\Entity\Street'); + expect($entity)->toBeAnInstanceOf(Street::class); expect($entity->getId())->toBe((int) $row['Identity']); expect($entity->getName())->toBe($row['Name']); expect($entity->getType())->toBe($row['Type']); @@ -222,81 +226,66 @@ public function followingStreetsShouldExistInDatabase(TableNode $table) } } - /** - * @return mixed - */ - private function getProvinceRepository() + private function getProvinceRepository(): EntityRepository { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:Province'); + ->getRepository(Province::class); } - /** - * @return mixed - */ - private function getDistrictRepository() + private function getDistrictRepository(): EntityRepository { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:District'); + ->getRepository(District::class); } - /** - * @return mixed - */ - private function getCommunityRepository() + private function getCommunityRepository(): EntityRepository { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:Community'); + ->getRepository(Community::class); } - /** - * @return mixed - */ - private function getPlaceTypeRepository() + private function getPlaceTypeRepository(): EntityRepository { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:PlaceType'); + ->getRepository(PlaceType::class); } - /** - * @return mixed - */ - private function getCommunityTypeRepository() + private function getCommunityTypeRepository(): EntityRepository { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:CommunityType'); + ->getRepository(CommunityType::class); } - private function getPlaceRepository() + private function getPlaceRepository(): EntityRepository { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:Place'); + ->getRepository(Place::class); } - private function getStreetRepository() + private function getStreetRepository(): EntityRepository { return $this->kernel ->getContainer() ->get('doctrine') ->getManager() - ->getRepository('FSiTerytDbBundle:Street'); + ->getRepository(Street::class); } } diff --git a/Behat/Fixtures/Project/app/AppKernel.php b/Behat/Fixtures/Project/app/AppKernel.php index 5bbdb22..39567c3 100644 --- a/Behat/Fixtures/Project/app/AppKernel.php +++ b/Behat/Fixtures/Project/app/AppKernel.php @@ -14,28 +14,27 @@ class AppKernel extends Kernel { - public function registerBundles() + public function registerBundles(): array { - return array( + return [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new FSi\Bundle\TerytDatabaseBundle\FSiTerytDbBundle(), new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), - ); + ]; } - - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(sprintf('%s/config/config_%s.yml', __DIR__, $this->getEnvironment())); } - public function getCacheDir() + public function getCacheDir(): string { return sys_get_temp_dir() . '/FSiTerytDbBundle/cache'; } - public function getLogDir() + public function getLogDir(): string { return sys_get_temp_dir() . '/FSiTerytDbBundle/logs'; } diff --git a/Behat/Fixtures/Project/app/bootstrap.php b/Behat/Fixtures/Project/app/bootstrap.php index 7bf2871..e234834 100644 --- a/Behat/Fixtures/Project/app/bootstrap.php +++ b/Behat/Fixtures/Project/app/bootstrap.php @@ -3,9 +3,9 @@ use Doctrine\Common\Annotations\AnnotationRegistry; if (!file_exists($file = __DIR__.'/../../../../vendor/autoload.php')) { - throw new \RuntimeException('Install the dependencies to run the test suite.'); + throw new RuntimeException('Install the dependencies to run the test suite.'); } $loader = require $file; -AnnotationRegistry::registerLoader(array($loader, 'loadClass')); \ No newline at end of file +AnnotationRegistry::registerLoader([$loader, 'loadClass']); diff --git a/Behat/Fixtures/Project/app/config/config_test.yml b/Behat/Fixtures/Project/app/config/config_test.yml index 6d959c6..64b1761 100644 --- a/Behat/Fixtures/Project/app/config/config_test.yml +++ b/Behat/Fixtures/Project/app/config/config_test.yml @@ -21,7 +21,7 @@ doctrine: memory: true orm: - auto_generate_proxy_classes: %kernel.debug% + auto_generate_proxy_classes: '%kernel.debug%' auto_mapping: true fsi_teryt_db: diff --git a/Command/TerytDownloadPlacesDatabaseCommand.php b/Command/TerytDownloadPlacesDatabaseCommand.php index 6bf6c08..47627aa 100644 --- a/Command/TerytDownloadPlacesDatabaseCommand.php +++ b/Command/TerytDownloadPlacesDatabaseCommand.php @@ -34,12 +34,14 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): ?int { $this->saveFile( $this->getApiClient()->getPlacesData(), $input->getArgument('target') ?? $this->getDefaultTargetPath(), $input->getArgument('filename') ); + + return 0; } } diff --git a/Command/TerytDownloadPlacesDictionaryDatabaseCommand.php b/Command/TerytDownloadPlacesDictionaryDatabaseCommand.php index 526539d..6d90182 100644 --- a/Command/TerytDownloadPlacesDictionaryDatabaseCommand.php +++ b/Command/TerytDownloadPlacesDictionaryDatabaseCommand.php @@ -34,12 +34,14 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): ?int { $this->saveFile( $this->getApiClient()->getPlacesDictionaryData(), $input->getArgument('target') ?? $this->getDefaultTargetPath(), $input->getArgument('filename') ); + + return 0; } } diff --git a/Command/TerytDownloadStreetsDatabaseCommand.php b/Command/TerytDownloadStreetsDatabaseCommand.php index de4cf43..7d23aa9 100644 --- a/Command/TerytDownloadStreetsDatabaseCommand.php +++ b/Command/TerytDownloadStreetsDatabaseCommand.php @@ -34,12 +34,14 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): ?int { $this->saveFile( $this->getApiClient()->getStreetsData(), $input->getArgument('target') ?? $this->getDefaultTargetPath(), $input->getArgument('filename') ); + + return 0; } } diff --git a/Command/TerytDownloadTerritorialDivisionDatabaseCommand.php b/Command/TerytDownloadTerritorialDivisionDatabaseCommand.php index 442c2e7..6989ad1 100644 --- a/Command/TerytDownloadTerritorialDivisionDatabaseCommand.php +++ b/Command/TerytDownloadTerritorialDivisionDatabaseCommand.php @@ -34,12 +34,14 @@ protected function configure(): void ); } - protected function execute(InputInterface $input, OutputInterface $output): void + protected function execute(InputInterface $input, OutputInterface $output): ?int { $this->saveFile( $this->getApiClient()->getTerritorialDivisionData(), $input->getArgument('target') ?? $this->getDefaultTargetPath(), $input->getArgument('filename') ); + + return 0; } } diff --git a/Command/TerytImportCommand.php b/Command/TerytImportCommand.php index cf2a256..29cf7d0 100644 --- a/Command/TerytImportCommand.php +++ b/Command/TerytImportCommand.php @@ -13,6 +13,7 @@ use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ObjectManager; +use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter; use Hobnob\XmlStreamReader\Parser; use SimpleXMLElement; use Symfony\Component\Console\Command\Command; @@ -22,7 +23,7 @@ abstract class TerytImportCommand extends Command { - const FLUSH_FREQUENCY = 2000; + public const FLUSH_FREQUENCY = 2000; /** * @var ManagerRegistry @@ -46,19 +47,11 @@ public function __construct(ManagerRegistry $managerRegistry) private $recordsCount = 0; - /** - * @param SimpleXMLElement $node - * @param ObjectManager $om - * @return \FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter - */ - abstract public function getNodeConverter(SimpleXMLElement $node, ObjectManager $om); + abstract public function getNodeConverter(SimpleXMLElement $node, ObjectManager $om): NodeConverter; - /** - * @return string - */ - abstract protected function getRecordXPath(); + abstract protected function getRecordXPath(): string; - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): ?int { $xmlFile = $input->getArgument('file'); @@ -82,11 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - /** - * @return Parser - * @throws \Exception - */ - private function createXmlParser() + private function createXmlParser(): Parser { $xmlParser = new Parser(); @@ -96,10 +85,7 @@ private function createXmlParser() ); } - /** - * @return callable - */ - private function getNodeParserCallbackFunction() + private function getNodeParserCallbackFunction(): callable { $counter = static::FLUSH_FREQUENCY; @@ -109,43 +95,33 @@ private function getNodeParserCallbackFunction() $this->recordsCount++; $counter--; - if (!$counter) { + if ($counter === 0) { $counter = static::FLUSH_FREQUENCY; $this->flushAndClear(); } }; } - /** - * @param SimpleXMLElement $node - */ - private function convertNodeToPersistedEntity(SimpleXMLElement $node) + private function convertNodeToPersistedEntity(SimpleXMLElement $node): void { $om = $this->getObjectManager(); - $converter = $this->getNodeConverter($node, $om); - $om->persist( - $converter->convertToEntity() - ); + $om->persist($this->getNodeConverter($node, $om)->convertToEntity()); } - private function updateProgressHelper() + private function updateProgressHelper(): void { $this->progressBar->setProgress(ftell($this->handle)); } - private function flushAndClear() + private function flushAndClear(): void { $this->getObjectManager()->flush(); $this->getObjectManager()->clear(); } - /** - * @param Parser $xmlParser - * @param string $xmlFile - */ - private function importXmlFile(Parser $xmlParser, $xmlFile) + private function importXmlFile(Parser $xmlParser, string $xmlFile): void { - $this->handle = fopen($xmlFile, 'r'); + $this->handle = fopen($xmlFile, 'rb'); $xmlParser->parse($this->handle); fclose($this->handle); } diff --git a/Command/TerytImportPlacesCommand.php b/Command/TerytImportPlacesCommand.php index 0b7ed78..c8c0188 100644 --- a/Command/TerytImportPlacesCommand.php +++ b/Command/TerytImportPlacesCommand.php @@ -12,36 +12,26 @@ namespace FSi\Bundle\TerytDatabaseBundle\Command; use Doctrine\Common\Persistence\ObjectManager; +use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter; use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\PlacesNodeConverter; +use SimpleXMLElement; use Symfony\Component\Console\Input\InputArgument; class TerytImportPlacesCommand extends TerytImportCommand { - protected function configure() + protected function configure(): void { $this->setName('teryt:import:places') ->setDescription('Import places data from xml to database') - ->addArgument( - 'file', - InputArgument::REQUIRED, - 'Places dictionary xml file' - ); + ->addArgument('file', InputArgument::REQUIRED, 'Places dictionary xml file'); } - /** - * @param \SimpleXMLElement $node - * @param \Doctrine\Common\Persistence\ObjectManager $om - * @return \FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter - */ - public function getNodeConverter(\SimpleXMLElement $node, ObjectManager $om) + public function getNodeConverter(SimpleXMLElement $node, ObjectManager $om): NodeConverter { return new PlacesNodeConverter($node, $om); } - /** - * @return string - */ - protected function getRecordXPath() + protected function getRecordXPath(): string { return '/simc/catalog/row'; } diff --git a/Command/TerytImportPlacesDictionaryCommand.php b/Command/TerytImportPlacesDictionaryCommand.php index 0bc28b4..5253299 100644 --- a/Command/TerytImportPlacesDictionaryCommand.php +++ b/Command/TerytImportPlacesDictionaryCommand.php @@ -12,36 +12,26 @@ namespace FSi\Bundle\TerytDatabaseBundle\Command; use Doctrine\Common\Persistence\ObjectManager; +use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter; use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\PlacesDictionaryNodeConverter; +use SimpleXMLElement; use Symfony\Component\Console\Input\InputArgument; class TerytImportPlacesDictionaryCommand extends TerytImportCommand { - protected function configure() + protected function configure(): void { $this->setName('teryt:import:places-dictionary') ->setDescription('Import places dictionary data from xml to database') - ->addArgument( - 'file', - InputArgument::REQUIRED, - 'Places dictionary xml file' - ); + ->addArgument('file', InputArgument::REQUIRED, 'Places dictionary xml file'); } - /** - * @param \SimpleXMLElement $node - * @param \Doctrine\Common\Persistence\ObjectManager $om - * @return \FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter - */ - public function getNodeConverter(\SimpleXMLElement $node, ObjectManager $om) + public function getNodeConverter(SimpleXMLElement $node, ObjectManager $om): NodeConverter { return new PlacesDictionaryNodeConverter($node, $om); } - /** - * @return string - */ - protected function getRecordXPath() + protected function getRecordXPath(): string { return '/simc/catalog/row'; } diff --git a/Command/TerytImportStreetsCommand.php b/Command/TerytImportStreetsCommand.php index e3f2cd2..bec3c45 100644 --- a/Command/TerytImportStreetsCommand.php +++ b/Command/TerytImportStreetsCommand.php @@ -12,36 +12,26 @@ namespace FSi\Bundle\TerytDatabaseBundle\Command; use Doctrine\Common\Persistence\ObjectManager; +use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter; use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\StreetsNodeConverter; +use SimpleXMLElement; use Symfony\Component\Console\Input\InputArgument; class TerytImportStreetsCommand extends TerytImportCommand { - protected function configure() + protected function configure(): void { $this->setName('teryt:import:streets') ->setDescription('Import streets data from xml to database') - ->addArgument( - 'file', - InputArgument::REQUIRED, - 'Places streets xml file' - ); + ->addArgument('file', InputArgument::REQUIRED, 'Places streets xml file'); } - /** - * @param \SimpleXMLElement $node - * @param \Doctrine\Common\Persistence\ObjectManager $om - * @return \FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter - */ - public function getNodeConverter(\SimpleXMLElement $node, ObjectManager $om) + public function getNodeConverter(SimpleXMLElement $node, ObjectManager $om): NodeConverter { return new StreetsNodeConverter($node, $om); } - /** - * @return string - */ - protected function getRecordXPath() + protected function getRecordXPath(): string { return '/ulic/catalog/row'; } diff --git a/Command/TerytImportTerritorialDivisionCommand.php b/Command/TerytImportTerritorialDivisionCommand.php index c2ce7ef..277e533 100644 --- a/Command/TerytImportTerritorialDivisionCommand.php +++ b/Command/TerytImportTerritorialDivisionCommand.php @@ -12,38 +12,28 @@ namespace FSi\Bundle\TerytDatabaseBundle\Command; use Doctrine\Common\Persistence\ObjectManager; +use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter; use FSi\Bundle\TerytDatabaseBundle\Teryt\Import\TerritorialDivisionNodeConverter; +use SimpleXMLElement; use Symfony\Component\Console\Input\InputArgument; class TerytImportTerritorialDivisionCommand extends TerytImportCommand { - const FLUSH_FREQUENCY = 1; + public const FLUSH_FREQUENCY = 1; - protected function configure() + protected function configure(): void { $this->setName('teryt:import:territorial-division') ->setDescription('Import teryt territorial division data from xml to database') - ->addArgument( - 'file', - InputArgument::REQUIRED, - 'Territorial division xml file' - ); + ->addArgument('file', InputArgument::REQUIRED, 'Territorial division xml file'); } - /** - * @param \SimpleXMLElement $node - * @param \Doctrine\Common\Persistence\ObjectManager $om - * @return \FSi\Bundle\TerytDatabaseBundle\Teryt\Import\NodeConverter - */ - public function getNodeConverter(\SimpleXMLElement $node, ObjectManager $om) + public function getNodeConverter(SimpleXMLElement $node, ObjectManager $om): NodeConverter { return new TerritorialDivisionNodeConverter($node, $om); } - /** - * @return string - */ - protected function getRecordXPath() + protected function getRecordXPath(): string { return '/teryt/catalog/row'; } diff --git a/DataFixtures/ORM/LoadCommunityTypeData.php b/DataFixtures/ORM/LoadCommunityTypeData.php index 8912b33..08e0036 100644 --- a/DataFixtures/ORM/LoadCommunityTypeData.php +++ b/DataFixtures/ORM/LoadCommunityTypeData.php @@ -17,7 +17,7 @@ class LoadCommunityTypeData implements ORMFixtureInterface { - protected $communityTypes = array( + protected $communityTypes = [ 1 => 'gmina miejska', 2 => 'gmina wiejska', 3 => 'gmina miejsko-wiejska', @@ -25,16 +25,12 @@ class LoadCommunityTypeData implements ORMFixtureInterface 5 => 'obszar wiejski w gminie miejsko-wiejskiej', 8 => 'dzielnica w m.st. Warszawa', 9 => 'delegatura gminy miejskiej' - ); + ]; - /** - * {@inheritDoc} - */ - public function load(ObjectManager $manager) + public function load(ObjectManager $manager): void { foreach ($this->communityTypes as $type => $name) { - $communityTypeEntity = new CommunityType($type); - $communityTypeEntity->setName($name); + $communityTypeEntity = new CommunityType($type, $name); $manager->persist($communityTypeEntity); $manager->flush(); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a822918..6252717 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -14,15 +14,9 @@ use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; -/** - * @author Norbert Orzechowicz - */ class Configuration implements ConfigurationInterface { - /** - * {@inheritdoc} - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('fsi_teryt_db'); diff --git a/DependencyInjection/FSITerytDbExtension.php b/DependencyInjection/FSITerytDbExtension.php index 2cdacc0..c972a4f 100644 --- a/DependencyInjection/FSITerytDbExtension.php +++ b/DependencyInjection/FSITerytDbExtension.php @@ -18,10 +18,7 @@ class FSITerytDbExtension extends Extension { - /** - * {@inheritdoc} - */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); diff --git a/Exception/TerritorialDivisionNodeConverterException.php b/Exception/TerritorialDivisionNodeConverterException.php index c8c9416..0976edb 100644 --- a/Exception/TerritorialDivisionNodeConverterException.php +++ b/Exception/TerritorialDivisionNodeConverterException.php @@ -11,6 +11,8 @@ namespace FSi\Bundle\TerytDatabaseBundle\Exception; -class TerritorialDivisionNodeConverterException extends \RuntimeException +use RuntimeException; + +class TerritorialDivisionNodeConverterException extends RuntimeException { } diff --git a/Model/Place/Place.php b/Model/Place/Place.php index 3fb5b7c..13c90cc 100644 --- a/Model/Place/Place.php +++ b/Model/Place/Place.php @@ -43,7 +43,7 @@ class Place protected $streets; /** - * @var Place + * @var Place|null */ protected $parentPlace; @@ -52,76 +52,47 @@ class Place */ protected $childPlaces; - /** - * @param int $id - */ - function __construct($id) + public function __construct(int $id, string $name, Type $type, Community $community) { $this->id = $id; + $this->name = $name; + $this->type = $type; + $this->community = $community; $this->streets = new ArrayCollection(); $this->childPlaces = new ArrayCollection(); } - /** - * @return int - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * @param Community $community - * @return Place - */ - public function setCommunity(Community $community) + public function setCommunity(Community $community): void { $this->community = $community; - - return $this; } - /** - * @return Community - */ - public function getCommunity() + public function getCommunity(): Community { return $this->community; } - /** - * @param string $name - * @return Place - */ - public function setName($name) + public function setName(string $name): void { $this->name = $name; - return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } - /** - * @param Type $type - * @return Place - */ - public function setType(Type $type) + public function setType(Type $type): void { $this->type = $type; - - return $this; } - /** - * @return Type - */ - public function getType() + public function getType(): Type { return $this->type; } @@ -129,23 +100,17 @@ public function getType() /** * @return Collection|Street[] */ - public function getStreets() + public function getStreets(): Collection { return $this->streets; } - /** - * @return Place - */ - public function getParentPlace() + public function getParentPlace(): ?Place { return $this->parentPlace; } - /** - * @param Place $parentPlace - */ - public function setParentPlace(Place $parentPlace = null) + public function setParentPlace(?Place $parentPlace): void { $this->parentPlace = $parentPlace; } @@ -153,15 +118,12 @@ public function setParentPlace(Place $parentPlace = null) /** * @return Collection|Place[] */ - public function getChildPlaces() + public function getChildPlaces(): Collection { return $this->childPlaces; } - /** - * @return string - */ - public function getFullName() + public function getFullName(): string { return sprintf('%s (%s)', $this->name, $this->type->getName()); } diff --git a/Model/Place/Street.php b/Model/Place/Street.php index c2d8ddf..107df74 100644 --- a/Model/Place/Street.php +++ b/Model/Place/Street.php @@ -38,102 +38,65 @@ class Street */ protected $place; - /** - * @param Place $place - * @param int $id - */ - public function __construct(Place $place, $id) + public function __construct(Place $place, int $id, string $type, ?string $additionalName, string $name) { $this->place = $place; $this->id = $id; + $this->type = $type; + $this->additionalName = $additionalName; + $this->name = $name; } - /** - * @return Place - */ - public function getPlace() + public function getPlace(): Place { return $this->place; } - /** - * @return int - */ - public function getId() + public function getId(): int { return $this->id; } - /** - * @param string $additionalName - * @return Street - */ - public function setAdditionalName($additionalName) + public function setAdditionalName(?string $additionalName): void { $this->additionalName = $additionalName; - - return $this; } - /** - * @return string - */ - public function getAdditionalName() + public function getAdditionalName(): ?string { return $this->additionalName; } - /** - * @param string $name - * @return Street - */ - public function setName($name) + public function setName(string $name): void { $this->name = $name; - - return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } - /** - * @param string $type - * @return Street - */ - public function setType($type) + public function setType(string $type): void { $this->type = $type; - - return $this; } - /** - * @return string - */ - public function getType() + public function getType(): string { return $this->type; } - /** - * @return string - */ - public function getFullName() + public function getFullName(): string { - $fullName = array($this->type); + $fullName = [$this->type]; - if (!empty($this->additionalName)) { + if ($this->additionalName !== null) { $fullName[] = $this->additionalName; } $fullName[] = $this->name; - return join(' ', $fullName); + return implode(' ', $fullName); } } diff --git a/Model/Place/Type.php b/Model/Place/Type.php index c137cf2..c6f24a8 100644 --- a/Model/Place/Type.php +++ b/Model/Place/Type.php @@ -12,11 +12,12 @@ namespace FSi\Bundle\TerytDatabaseBundle\Model\Place; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; class Type { /** - * @var string + * @var int */ protected $type; @@ -26,50 +27,36 @@ class Type protected $name; /** - * @var \Doctrine\Common\Collections\ArrayCollection + * @var Collection|Place[] */ protected $places; - /** - * @param int $type - */ - function __construct($type) + public function __construct(int $type, string $name) { $this->type = $type; + $this->name = $name; $this->places = new ArrayCollection(); } - /** - * @return mixed - */ - public function getType() + public function getType(): int { return $this->type; } - /** - * @param mixed $name - * @return \FSi\Bundle\TerytDatabaseBundle\Model\Place\Type - */ - public function setName($name) + public function setName(string $name): void { $this->name = $name; - - return $this; } - /** - * @return mixed - */ - public function getName() + public function getName(): string { return $this->name; } /** - * @return ArrayCollection + * @return Collection|Place[] */ - public function getPlaces() + public function getPlaces(): Collection { return $this->places; } diff --git a/Model/Territory/Community.php b/Model/Territory/Community.php index 9bf98fc..1467b25 100644 --- a/Model/Territory/Community.php +++ b/Model/Territory/Community.php @@ -32,49 +32,26 @@ class Community extends Territory */ protected $places; - /** - * @param int $code - */ - public function __construct($code) + public function __construct(District $district, int $code, string $name, CommunityType $type) { - parent::__construct($code); - $this->places = new ArrayCollection(); - } + parent::__construct($code, $name); - /** - * @param District $district - * @return self - */ - public function setDistrict(District $district) - { $this->district = $district; - - return $this; + $this->type = $type; + $this->places = new ArrayCollection(); } - /** - * @return District - */ - public function getDistrict() + public function getDistrict(): District { return $this->district; } - /** - * @param CommunityType $type - * @return self - */ - public function setType(CommunityType $type) + public function setType(CommunityType $type): void { $this->type = $type; - - return $this; } - /** - * @return CommunityType - */ - public function getType() + public function getType(): CommunityType { return $this->type; } @@ -87,11 +64,8 @@ public function getPlaces() return $this->places; } - /** - * @return string - */ - public function getFullName() + public function getFullName(): string { - return sprintf('%s (%s)', $this->name, $this->type->getName()); + return sprintf('%s (%s)', $this->getName(), $this->type->getName()); } } diff --git a/Model/Territory/CommunityType.php b/Model/Territory/CommunityType.php index fe5d029..5bf47cb 100644 --- a/Model/Territory/CommunityType.php +++ b/Model/Territory/CommunityType.php @@ -31,38 +31,24 @@ class CommunityType */ protected $communities; - /** - * @param int $type - */ - public function __construct($type) + public function __construct(int $type, string $name) { $this->type = $type; + $this->name = $name; $this->communities = new ArrayCollection(); } - /** - * @return int - */ - public function getType() + public function getType(): int { return $this->type; } - /** - * @param string $name - * @return CommunityType - */ - public function setName($name) + public function setName(string $name): void { $this->name = $name; - - return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } diff --git a/Model/Territory/District.php b/Model/Territory/District.php index 1d6550a..285a9a3 100644 --- a/Model/Territory/District.php +++ b/Model/Territory/District.php @@ -26,30 +26,15 @@ class District extends Territory */ protected $communities; - /** - * @param int $code - */ - function __construct($code) + public function __construct(Province $province, int $code, string $name) { - parent::__construct($code); - $this->communities = new ArrayCollection(); - } + parent::__construct($code, $name); - /** - * @param Province $province - * @return District - */ - public function setProvince(Province $province) - { $this->province = $province; - - return $this; + $this->communities = new ArrayCollection(); } - /** - * @return Province - */ - public function getProvince() + public function getProvince(): Province { return $this->province; } diff --git a/Model/Territory/Province.php b/Model/Territory/Province.php index afc5000..371d107 100644 --- a/Model/Territory/Province.php +++ b/Model/Territory/Province.php @@ -21,12 +21,10 @@ class Province extends Territory */ protected $districts; - /** - * @param int $code - */ - public function __construct($code) + public function __construct(int $code, string $name) { - parent::__construct($code); + parent::__construct($code, $name); + $this->districts = new ArrayCollection(); } diff --git a/Model/Territory/Territory.php b/Model/Territory/Territory.php index abda7f6..755817a 100644 --- a/Model/Territory/Territory.php +++ b/Model/Territory/Territory.php @@ -23,37 +23,23 @@ class Territory */ protected $name; - /** - * @param int $code - */ - public function __construct($code) + public function __construct(int $code, string $name) { $this->code = $code; + $this->name = $name; } - /** - * @return int - */ - public function getCode() + public function getCode(): int { return $this->code; } - /** - * @param string $name - * @return self - */ - public function setName($name) + public function setName(string $name): void { $this->name = $name; - - return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } diff --git a/README.md b/README.md index 7300f92..7877d72 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,12 @@ Register bundles in `AppKernel.php` ```php public function registerBundles() { - return array( + return [ // ... new FSi\Bundle\TerytDatabaseBundle\FSiTerytDbBundle(), new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(), // ... - ); + ]; } ``` diff --git a/Teryt/Api/Client.php b/Teryt/Api/Client.php index 3270f51..ccaa74e 100644 --- a/Teryt/Api/Client.php +++ b/Teryt/Api/Client.php @@ -11,6 +11,7 @@ namespace FSi\Bundle\TerytDatabaseBundle\Teryt\Api; +use DateTime; use SoapClient; use SplTempFileObject; @@ -68,7 +69,7 @@ public function getPlacesDictionaryData() : SplTempFileObject private function getFile($functionName): SplTempFileObject { $response = $this->makeCall($functionName, [ - 'DataStanu' => (new \DateTime())->format('Y-m-d') + 'DataStanu' => (new DateTime())->format('Y-m-d') ]); $resultKey = $functionName . 'Result'; diff --git a/Teryt/Api/TerytSoapClient.php b/Teryt/Api/TerytSoapClient.php index a407dea..20829b6 100644 --- a/Teryt/Api/TerytSoapClient.php +++ b/Teryt/Api/TerytSoapClient.php @@ -39,7 +39,7 @@ public function addUserToken(string $username, string $password, bool $digest = $this->digest = $digest; } - public function __doRequest($request, $location, $action, $version, $one_way = 0) + public function __doRequest($request, $location, $action, $version, $one_way = 0): string { $doc = new DOMDocument('1.0'); $doc->loadXML($request); diff --git a/Teryt/Api/WSASoap.php b/Teryt/Api/WSASoap.php index e4641b4..579aaca 100644 --- a/Teryt/Api/WSASoap.php +++ b/Teryt/Api/WSASoap.php @@ -22,10 +22,10 @@ class WSASoap const WSANS = 'http://www.w3.org/2005/08/addressing'; const WSAPFX = 'wsa'; private $soapNS, $soapPFX; - private $soapDoc = null; - private $envelope = null; - private $SOAPXPath = null; - private $header = null; + private $soapDoc; + private $envelope; + private $SOAPXPath; + private $header; public function __construct(DOMDocument $doc) { diff --git a/Teryt/Import/NodeConverter.php b/Teryt/Import/NodeConverter.php index 460e44a..f42b260 100644 --- a/Teryt/Import/NodeConverter.php +++ b/Teryt/Import/NodeConverter.php @@ -12,20 +12,21 @@ namespace FSi\Bundle\TerytDatabaseBundle\Teryt\Import; use Doctrine\Common\Persistence\ObjectManager; +use SimpleXMLElement; abstract class NodeConverter { /** - * @var \SimpleXMLElement + * @var SimpleXMLElement */ protected $node; /** - * @var \Doctrine\Common\Persistence\ObjectManager + * @var ObjectManager */ protected $om; - public function __construct(\SimpleXMLElement $node, ObjectManager $om) + public function __construct(SimpleXMLElement $node, ObjectManager $om) { $this->node = $node; $this->om = $om; diff --git a/Teryt/Import/PlacesDictionaryNodeConverter.php b/Teryt/Import/PlacesDictionaryNodeConverter.php index 66a9c67..69f0628 100644 --- a/Teryt/Import/PlacesDictionaryNodeConverter.php +++ b/Teryt/Import/PlacesDictionaryNodeConverter.php @@ -12,40 +12,29 @@ namespace FSi\Bundle\TerytDatabaseBundle\Teryt\Import; use FSi\Bundle\TerytDatabaseBundle\Entity\PlaceType; -use SimpleXMLElement; class PlacesDictionaryNodeConverter extends NodeConverter { - public function convertToEntity() + public function convertToEntity(): PlaceType { - $placeType = $this->createPlaceTypeEntity(); - $placeType->setName($this->getPlaceName()); + /** @var PlaceType|null $placeType */ + $placeType = $this->findOneBy(PlaceType::class, ['type' => $this->getPlaceType()]); - return $placeType; - } + if ($placeType === null) { + return new PlaceType($this->getPlaceType(), $this->getPlaceTypeName()); + } - /** - * @return PlaceType - */ - private function createPlaceTypeEntity() - { - return $this->findOneBy(PlaceType::class, array( - 'type' => $this->getPlaceType() - )) ?: new PlaceType($this->getPlaceType()); + $placeType->setName($this->getPlaceTypeName()); + + return $placeType; } - /** - * @return int - */ - private function getPlaceType() + private function getPlaceType(): int { return (int) $this->node->rm->__toString(); } - /** - * @return string - */ - private function getPlaceName() + private function getPlaceTypeName(): string { return trim((string) $this->node->nazwa_rm->__toString()); } diff --git a/Teryt/Import/PlacesNodeConverter.php b/Teryt/Import/PlacesNodeConverter.php index 1418621..bd93737 100644 --- a/Teryt/Import/PlacesNodeConverter.php +++ b/Teryt/Import/PlacesNodeConverter.php @@ -17,118 +17,86 @@ class PlacesNodeConverter extends NodeConverter { - public function convertToEntity() + public function convertToEntity(): Place { - $placeEntity = $this->createPlaceEntity(); - $placeEntity->setName($this->getPlaceName()) - ->setCommunity($this->getPlaceCommunity()) - ->setType($this->getPlaceType()) - ->setParentPlace($this->getParentPlace()); + /** @var Place|null $placeEntity */ + $placeEntity = $this->findOneBy(Place::class, ['id' => $this->getPlaceId()]); + + if ($placeEntity !== null) { + $placeEntity->setName($this->getPlaceName()); + $placeEntity->setType($this->getPlaceType()); + $placeEntity->setCommunity($this->getPlaceCommunity()); + } else { + $placeEntity = new Place( + $this->getPlaceId(), + $this->getPlaceName(), + $this->getPlaceType(), + $this->getPlaceCommunity() + ); + } - return $placeEntity; - } + $placeEntity->setParentPlace($this->getParentPlace()); - /** - * @return Place - */ - private function createPlaceEntity() - { - return $this->findOneBy(Place::class, array( - 'id' => $this->getPlaceId() - )) ?: new Place($this->getPlaceId()); + return $placeEntity; } - /** - * @return int - */ - private function getDistrictCode() + private function getDistrictCode(): int { return (int) $this->node->pow->__toString(); } - /** - * @return int - */ - private function getProvinceCode() + private function getProvinceCode(): int { return (int) $this->node->woj->__toString(); } - /** - * @return int - */ - private function getCommunityCode() + private function getCommunityCode(): int { return (int) $this->node->gmi->__toString(); } - /** - * @return int - */ - private function getPlaceDictionaryType() + private function getPlaceDictionaryType(): int { return (int) $this->node->rm->__toString(); } - /** - * @return int - */ - private function getPlaceId() + private function getPlaceId(): int { return (int) $this->node->sym->__toString(); } - /** - * @return int - */ - private function getParentPlaceId() + private function getParentPlaceId(): int { return (int) $this->node->sympod->__toString(); } - /** - * @return string - */ - private function getPlaceName() + private function getPlaceName(): string { return (string) $this->node->nazwa->__toString(); } - /** - * @return Community - */ - private function getPlaceCommunity() + private function getPlaceCommunity(): Community { - return $this->findOneBy(Community::class, array( + return $this->findOneBy(Community::class, [ 'code' => (int) sprintf( - "%d%02d%02d%1d", + '%d%02d%02d%1d', $this->getProvinceCode(), $this->getDistrictCode(), $this->getCommunityCode(), $this->node->rodz_gmi->__toString() ) - )); + ]); } - /** - * @return PlaceType - */ - private function getPlaceType() + private function getPlaceType(): PlaceType { - return $this->findOneBy(PlaceType::class, array( - 'type' => $this->getPlaceDictionaryType() - )); + return $this->findOneBy(PlaceType::class, ['type' => $this->getPlaceDictionaryType()]); } - /** - * @return Place - */ - private function getParentPlace() + private function getParentPlace(): ?Place { if ($this->getParentPlaceId() && ($this->getParentPlaceId() !== $this->getPlaceId())) { - return $this->findOneBy(Place::class, [ - 'id' => $this->getParentPlaceId() - ]); + return $this->findOneBy(Place::class, ['id' => $this->getParentPlaceId()]); } return null; diff --git a/Teryt/Import/StreetsNodeConverter.php b/Teryt/Import/StreetsNodeConverter.php index 8e4b06f..a4bc898 100644 --- a/Teryt/Import/StreetsNodeConverter.php +++ b/Teryt/Import/StreetsNodeConverter.php @@ -16,70 +16,59 @@ class StreetsNodeConverter extends NodeConverter { - public function convertToEntity() - { - $streetEntity = $this->createStreetEntity(); - $streetEntity->setName($this->getName()) - ->setAdditionalName($this->getAdditionalName()) - ->setType($this->getStreetType()); - - return $streetEntity; - } - - /** - * @return Street - */ - private function createStreetEntity() + public function convertToEntity(): Street { $place = $this->getPlace(); - return $this->findOneBy('FSiTerytDbBundle:Street', array( + /** @var Street|null $streetEntity */ + $streetEntity = $this->findOneBy('FSiTerytDbBundle:Street', [ 'id' => $this->getStreetId(), 'place' => $place - )) ?: new Street($place, $this->getStreetId()); + ]); + + if ($streetEntity === null) { + return new Street( + $place, + $this->getStreetId(), + $this->getStreetType(), + $this->getAdditionalName(), + $this->getName() + ); + } + + $streetEntity->setType($this->getStreetType()); + $streetEntity->setName($this->getName()); + $streetEntity->setAdditionalName($this->getAdditionalName()); + + return $streetEntity; } - /** - * @return string - */ - private function getStreetId() + private function getStreetId(): int { return (int) $this->node->sym_ul->__toString(); } - /** - * @return string - */ - private function getName() + private function getName(): string { return trim((string) $this->node->nazwa_1); } - /** - * @return string - */ - private function getAdditionalName() + private function getAdditionalName(): ?string { $additionalName = trim((string) $this->node->nazwa_2); return $additionalName ?: null; } - /** - * @return string - */ - private function getStreetType() + private function getStreetType(): string { return (string) $this->node->cecha; } - /** - * @return Place - */ - private function getPlace() + private function getPlace(): Place { - return $this->om->getRepository(Place::class)->findOneBy(array( + return $this->om->getRepository(Place::class)->findOneBy([ 'id' => (int) $this->node->sym->__toString() - )); + ]); } } diff --git a/Teryt/Import/TerritorialDivisionNodeConverter.php b/Teryt/Import/TerritorialDivisionNodeConverter.php index ec1e037..0581bc3 100644 --- a/Teryt/Import/TerritorialDivisionNodeConverter.php +++ b/Teryt/Import/TerritorialDivisionNodeConverter.php @@ -16,6 +16,7 @@ use FSi\Bundle\TerytDatabaseBundle\Entity\District; use FSi\Bundle\TerytDatabaseBundle\Entity\Province; use FSi\Bundle\TerytDatabaseBundle\Exception\TerritorialDivisionNodeConverterException; +use RuntimeException; class TerritorialDivisionNodeConverter extends NodeConverter { @@ -37,110 +38,73 @@ public function convertToEntity() return $this->convertToCommunity(); } - throw new TerritorialDivisionNodeConverterException(); + throw new TerritorialDivisionNodeConverterException('Unknown territory type'); } - /** - * @return bool - */ - private function isProvinceNode() + private function isProvinceNode(): bool { return $this->hasProvinceCode() && !$this->hasDistrictCode(); } - /** - * @return bool - */ - private function isDistrict() + private function isDistrict(): bool { return $this->hasProvinceCode() && $this->hasDistrictCode() && !$this->hasCommunityCode(); } - /** - * @return bool - */ - public function isCommunity() + public function isCommunity(): bool { return $this->hasProvinceCode() && $this->hasDistrictCode() && $this->hasCommunityCode(); } - /** - * @return Province - */ - private function convertToProvince() + private function convertToProvince(): Province { - $provinceEntity = $this->createProvinceEntity(); + /** @var Province|null $provinceEntity */ + $provinceEntity = $this->findOneBy(Province::class, ['code' => $this->getProvinceCode()]); + if ($provinceEntity === null) { + return new Province($this->getProvinceCode(), $this->getTerritoryName()); + } + $provinceEntity->setName($this->getTerritoryName()); return $provinceEntity; } - /** - * @return District - */ - private function convertToDistrict() - { - $province = $this->findOneBy(Province::class, array( - 'code' => $this->getProvinceCode() - )); - - return $this->createDistrictEntity() - ->setName($this->getTerritoryName()) - ->setProvince($province); - } - - /** - * @return Community - */ - private function convertToCommunity() + private function convertToDistrict(): District { - $district = $this->findOneBy(District::class, array( - 'code' => (int) sprintf('%1d%02d', $this->getProvinceCode(), $this->getDistrictCode()) - )); + /** @var Province|null $province */ + $province = $this->findOneBy(Province::class, ['code' => $this->getProvinceCode()]); + if ($province === null) { + throw new RuntimeException(sprintf('Unable to find province "%s"', $this->getProvinceCode())); + } - $type = $this->findOneBy(CommunityType::class, array( - 'type' => (int) $this->node->rodz->__toString() - )); + $districtCode = (int) sprintf('%d%02d', $this->getProvinceCode(), $this->getDistrictCode()); + /** @var District|null $district */ + $district = $this->findOneBy(District::class, ['code' => $districtCode]); - if (!$type) { - throw new \RuntimeException(sprintf('Unable to find community type "%s"', $this->node->rodz)); + if ($district === null) { + return new District($province, $districtCode, $this->getTerritoryName()); } - $community = $this->createCommunityEntity(); - $community->setName($this->getTerritoryName()); - $community->setType($type); - $community->setDistrict($district); + $district->setName($this->getTerritoryName()); - return $community; + return $district; } - /** - * @return Province - */ - private function createProvinceEntity() - { - return $this->findOneBy(Province::class, array( - 'code' => $this->getProvinceCode() - )) ?: new Province($this->getProvinceCode()); - } - - /** - * @return District - */ - private function createDistrictEntity() + private function convertToCommunity(): Community { - $districtCode = (int) sprintf('%d%02d', $this->getProvinceCode(), $this->getDistrictCode()); + $districtCode = (int) sprintf('%1d%02d', $this->getProvinceCode(), $this->getDistrictCode()); + /** @var District|null $district */ + $district = $this->findOneBy(District::class, ['code' => $districtCode]); + if ($district === null) { + throw new RuntimeException(sprintf('Unable to find district "%s"', $districtCode)); + } - return $this->findOneBy(District::class, array( - 'code' => $districtCode - )) ?: new District($districtCode); - } + /** @var CommunityType|null $type */ + $type = $this->findOneBy(CommunityType::class, ['type' => (int) $this->node->rodz->__toString()]); + if ($type === null) { + throw new RuntimeException(sprintf('Unable to find community type "%s"', $this->node->rodz->__toString())); + } - /** - * @return Community - */ - private function createCommunityEntity() - { $communityCode = (int) sprintf( '%d%02d%02d%1d', $this->getProvinceCode(), @@ -148,72 +112,55 @@ private function createCommunityEntity() $this->getCommunityCode(), $this->getCommunityType() ); + /** @var Community|null $community */ + $community = $this->findOneBy(Community::class, ['code' => $communityCode]); - return $this->findOneBy(Community::class, array( - 'code' => $communityCode - )) ?: new Community($communityCode); + if ($community === null) { + return new Community($district, $communityCode, $this->getTerritoryName(), $type); + } + + $community->setName($this->getTerritoryName()); + $community->setType($type); + + return $community; } - /** - * @return int - */ - public function getDistrictCode() + public function getDistrictCode(): int { return (int) $this->node->pow->__toString(); } - /** - * @return bool - */ - private function hasProvinceCode() + private function hasProvinceCode(): bool { return !empty(trim($this->node->woj->__toString())); } - /** - * @return int - */ - private function getProvinceCode() + private function getProvinceCode(): int { return (int) $this->node->woj->__toString(); } - /** - * @return bool - */ - public function hasDistrictCode() + public function hasDistrictCode(): bool { return !empty(trim($this->node->pow->__toString())); } - /** - * @return bool - */ - public function hasCommunityCode() + public function hasCommunityCode(): bool { return !empty(trim($this->node->gmi->__toString())); } - /** - * @return int - */ - private function getCommunityCode() + private function getCommunityCode(): int { return (int) $this->node->gmi->__toString(); } - /** - * @return string - */ - private function getTerritoryName() + private function getTerritoryName(): string { return (string) $this->node->nazwa; } - /** - * @return int - */ - private function getCommunityType() + private function getCommunityType(): int { return (int) $this->node->rodz->__toString(); } diff --git a/behat.yml b/behat.yml index 7e28a9d..0f43774 100644 --- a/behat.yml +++ b/behat.yml @@ -1,17 +1,17 @@ default: suites: default: - paths: [ %paths.base%/Features ] + paths: [ '%paths.base%/Features' ] contexts: - FSi\Bundle\TerytDatabaseBundle\Behat\Context\CommandContext: - fixturesPath: %paths.base%/Behat/Fixtures + fixturesPath: '%paths.base%/Behat/Fixtures' - FSi\Bundle\TerytDatabaseBundle\Behat\Context\DataContext - FSi\Bundle\TerytDatabaseBundle\Behat\Context\DownloadTerytCommandContext: - fixturesPath: %paths.base%/Behat/Fixtures + fixturesPath: '%paths.base%/Behat/Fixtures' - FSi\Bundle\TerytDatabaseBundle\Behat\Context\CommandContext: - fixturesPath: %paths.base%/Behat/Fixtures + fixturesPath: '%paths.base%/Behat/Fixtures' - FSi\Bundle\TerytDatabaseBundle\Behat\Context\ImportTerytCommandContext: - fixturesPath: %paths.base%/Behat/Fixtures + fixturesPath: '%paths.base%/Behat/Fixtures' extensions: Behat\Symfony2Extension: kernel: diff --git a/composer.json b/composer.json index a0096a5..aa56770 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ "symfony/console": "^3.4|^4.0", "symfony/dom-crawler": "^3.4|^4.0", "symfony/css-selector": "^3.4|^4.0", - "doctrine/common": "^2.5", + "doctrine/common": "^2.6", "hobnob/xml-stream-reader": "^1.0", "doctrine/doctrine-fixtures-bundle": "^3.1", "robrichards/wse-php": "^2.0", @@ -33,8 +33,10 @@ "behat/symfony2-extension": "^2.0", "behat/mink-extension": "^2.0", "behat/mink-browserkit-driver": "^1.3", - "phpspec/phpspec": "^3.1", - "bossa/phpspec2-expect": "^2.1" + "phpspec/phpspec": "^5.0", + "bossa/phpspec2-expect": "^3.0", + "phpstan/phpstan": "^0.11.4", + "phpstan/phpstan-doctrine": "^0.11.2" }, "config": { "bin-dir": "bin" @@ -42,6 +44,9 @@ "autoload": { "psr-4": { "FSi\\Bundle\\TerytDatabaseBundle\\": "" } }, + "autoload-dev": { + "psr-4": { "spec\\": "spec" } + }, "extra": { "branch-alias": { "dev-master": "4.0-dev" diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..98a4bc4 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,10 @@ +includes: + - vendor/phpstan/phpstan-doctrine/extension.neon +parameters: + paths: + - Behat/Context + - Command + - DataFixtures + - Entity + - Model + - Teryt diff --git a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesDictionaryNodeConverterSpec.php b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesDictionaryNodeConverterSpec.php index 489f283..8815456 100644 --- a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesDictionaryNodeConverterSpec.php +++ b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesDictionaryNodeConverterSpec.php @@ -16,18 +16,19 @@ use FSi\Bundle\TerytDatabaseBundle\Entity\PlaceType; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use SimpleXMLElement; class PlacesDictionaryNodeConverterSpec extends ObjectBehavior { - function let(ObjectManager $om, ObjectRepository $or) + function let(ObjectManager $om, ObjectRepository $or): void { // It is not possible to mock internal classes with final constructor - $this->beConstructedWith(new \SimpleXMLElement(''), $om); + $this->beConstructedWith(new SimpleXMLElement(''), $om); $om->getRepository(Argument::type('string'))->willReturn($or); $or->findOneBy(Argument::type('array'))->willReturn(); } - function it_converts_node_to_places_dictionary_entry(ObjectManager $om) + function it_converts_node_to_places_dictionary_entry(ObjectManager $om): void { $xml = << @@ -37,16 +38,15 @@ function it_converts_node_to_places_dictionary_entry(ObjectManager $om) EOT; - $placeType = new PlaceType(2); - $placeType->setName('kolonia'); + $placeType = new PlaceType(2, 'kolonia'); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($placeType); } function it_converts_node_to_places_dictionary_entry_with_updating_existing_one( ObjectManager $om, ObjectRepository $or, PlaceType $placeType - ){ + ): void { $xml = << 02 @@ -55,13 +55,11 @@ function it_converts_node_to_places_dictionary_entry_with_updating_existing_one( EOT; - $or->findOneBy(array( - 'type' => 2 - ))->shouldBeCalled()->willReturn($placeType); + $or->findOneBy(['type' => 2])->shouldBeCalled()->willReturn($placeType); - $placeType->setName('kolonia')->shouldBeCalled()->willReturn($placeType); + $placeType->setName('kolonia')->shouldBeCalled(); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($placeType); } } diff --git a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesNodeConverterSpec.php b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesNodeConverterSpec.php index 7575e56..5bed7ad 100644 --- a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesNodeConverterSpec.php +++ b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/PlacesNodeConverterSpec.php @@ -14,22 +14,26 @@ use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectRepository; use FSi\Bundle\TerytDatabaseBundle\Entity\Community; +use FSi\Bundle\TerytDatabaseBundle\Entity\CommunityType; +use FSi\Bundle\TerytDatabaseBundle\Entity\District; use FSi\Bundle\TerytDatabaseBundle\Entity\Place; -use FSi\Bundle\TerytDatabaseBundle\Model\Place\Type; +use FSi\Bundle\TerytDatabaseBundle\Entity\PlaceType; +use FSi\Bundle\TerytDatabaseBundle\Entity\Province; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use SimpleXMLElement; class PlacesNodeConverterSpec extends ObjectBehavior { - function let(ObjectManager $om, ObjectRepository $or) + function let(ObjectManager $om, ObjectRepository $or): void { // It is not possible to mock internal classes with final constructor - $this->beConstructedWith(new \SimpleXMLElement(''), $om); + $this->beConstructedWith(new SimpleXMLElement(''), $om); $om->getRepository(Argument::type('string'))->willReturn($or); $or->findOneBy(Argument::type('array'))->willReturn(); } - function it_converts_node_to_place_entry(ObjectManager $om, ObjectRepository $or) + function it_converts_node_to_place_entry(ObjectManager $om, ObjectRepository $or): void { $xml = << @@ -46,31 +50,27 @@ function it_converts_node_to_place_entry(ObjectManager $om, ObjectRepository $or EOT; - $community = new Community(41105); + $community = new Community( + new District(new Province(1, 'województwo'), 1, 'Powiat'), + 41105, + 'Gmina', + new CommunityType(1, 'Gmina wiejska') + ); - $placeType = new Type(1); - $placeType->setName('miasto'); + $placeType = new PlaceType(1, 'miasto'); - $or->findOneBy(array( - 'code' => 411055 - ))->shouldBeCalled()->willReturn($community); + $or->findOneBy(['code' => 411055])->shouldBeCalled()->willReturn($community); + $or->findOneBy(['type' => 1])->shouldBeCalled()->willReturn($placeType); - $or->findOneBy(array( - 'type' => 1 - ))->shouldBeCalled()->willReturn($placeType); + $place = new Place(867650, 'Rzeczyca', $placeType, $community); - $place = new Place(867650); - $place->setName('Rzeczyca') - ->setType($placeType) - ->setCommunity($community); - - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($place); } function it_converts_node_to_place_with_updating_existing_one( ObjectManager $om, ObjectRepository $or, Place $place - ) { + ): void { $xml = << 04 @@ -86,35 +86,31 @@ function it_converts_node_to_place_with_updating_existing_one( EOT; - $community = new Community(41105); - - $placeType = new Type(1); - $placeType->setName('miasto'); - - $or->findOneBy(array( - 'id' => 867650 - ))->shouldBeCalled()->willReturn($place); + $community = new Community( + new District(new Province(1, 'województwo'), 1, 'Powiat'), + 41105, + 'Gmina', + new CommunityType(1, 'Gmina wiejska') + ); - $or->findOneBy(array( - 'code' => 411055 - ))->shouldBeCalled()->willReturn($community); + $placeType = new PlaceType(1, 'miasto'); - $or->findOneBy(array( - 'type' => '01' - ))->shouldBeCalled()->willReturn($placeType); + $or->findOneBy(['id' => 867650])->shouldBeCalled()->willReturn($place); + $or->findOneBy(['code' => 411055])->shouldBeCalled()->willReturn($community); + $or->findOneBy(['type' => '01'])->shouldBeCalled()->willReturn($placeType); - $place->setName('Rzeczyca')->shouldBeCalled()->willReturn($place); - $place->setType($placeType)->shouldBeCalled()->willReturn($place); - $place->setCommunity($community)->shouldBeCalled()->willReturn($place); - $place->setParentPlace(null)->shouldBeCalled()->willReturn($place); + $place->setName('Rzeczyca')->shouldBeCalled(); + $place->setType($placeType)->shouldBeCalled(); + $place->setCommunity($community)->shouldBeCalled(); + $place->setParentPlace(null)->shouldBeCalled(); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($place->getWrappedObject()); } function it_updates_parent_place_in_existing_place( ObjectManager $om, ObjectRepository $or, Place $place, Place $parentPlace - ) { + ): void { $xml = << 04 @@ -130,33 +126,26 @@ function it_updates_parent_place_in_existing_place( EOT; - $community = new Community(41105); - - $placeType = new Type(1); - $placeType->setName('miasto'); - - $or->findOneBy(array( - 'id' => 867650 - ))->shouldBeCalled()->willReturn($place); - - $or->findOneBy(array( - 'id' => 867643 - ))->shouldBeCalled()->willReturn($parentPlace); + $community = new Community( + new District(new Province(1, 'województwo'), 1, 'Powiat'), + 41105, + 'Gmina', + new CommunityType(1, 'Gmina wiejska') + ); - $or->findOneBy(array( - 'code' => 411055 - ))->shouldBeCalled()->willReturn($community); + $placeType = new PlaceType(1, 'miasto'); - $or->findOneBy(array( - 'type' => 1 - ))->shouldBeCalled()->willReturn($placeType); + $or->findOneBy(['id' => 867650])->shouldBeCalled()->willReturn($place); + $or->findOneBy(['id' => 867643])->shouldBeCalled()->willReturn($parentPlace); + $or->findOneBy(['code' => 411055])->shouldBeCalled()->willReturn($community); + $or->findOneBy(['type' => 1])->shouldBeCalled()->willReturn($placeType); - $place->setName('Rzeczyca')->shouldBeCalled()->willReturn($place); - $place->setType($placeType)->shouldBeCalled()->willReturn($place); - $place->setCommunity($community)->shouldBeCalled()->willReturn($place); - $place->setParentPlace($parentPlace)->shouldBeCalled()->willReturn($place); + $place->setName('Rzeczyca')->shouldBeCalled(); + $place->setType($placeType)->shouldBeCalled(); + $place->setCommunity($community)->shouldBeCalled(); + $place->setParentPlace($parentPlace)->shouldBeCalled(); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($place->getWrappedObject()); } } diff --git a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/StreetsNodeConverterSpec.php b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/StreetsNodeConverterSpec.php index 6c6026c..81317e9 100644 --- a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/StreetsNodeConverterSpec.php +++ b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/StreetsNodeConverterSpec.php @@ -13,22 +13,29 @@ use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectRepository; +use FSi\Bundle\TerytDatabaseBundle\Entity\Community; +use FSi\Bundle\TerytDatabaseBundle\Entity\CommunityType; +use FSi\Bundle\TerytDatabaseBundle\Entity\District; use FSi\Bundle\TerytDatabaseBundle\Entity\Place; +use FSi\Bundle\TerytDatabaseBundle\Entity\PlaceType; +use FSi\Bundle\TerytDatabaseBundle\Entity\Province; use FSi\Bundle\TerytDatabaseBundle\Entity\Street; +use FSi\Bundle\TerytDatabaseBundle\Model\Place\Type; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use SimpleXMLElement; class StreetsNodeConverterSpec extends ObjectBehavior { - function let(ObjectManager $om, ObjectRepository $or) + function let(ObjectManager $om, ObjectRepository $or): void { // It is not possible to mock internal classes with final constructor - $this->beConstructedWith(new \SimpleXMLElement(''), $om); + $this->beConstructedWith(new SimpleXMLElement(''), $om); $om->getRepository(Argument::type('string'))->willReturn($or); $or->findOneBy(Argument::type('array'))->willReturn(); } - function it_converts_node_to_street_entry(ObjectManager $om, ObjectRepository $or) + function it_converts_node_to_street_entry(ObjectManager $om, ObjectRepository $or): void { $xml = << @@ -45,25 +52,25 @@ function it_converts_node_to_street_entry(ObjectManager $om, ObjectRepository $o 2013-10-10 EOT; - $place = new Place(884849); - $place->setName('City'); + $community = new Community( + new District(new Province(1, 'województwo'), 1, 'Powiat'), + 1, + 'Gmina', + new CommunityType(1, 'Gmina wiejska') + ); + $place = new Place(884849, 'City', new PlaceType(1, 'wieś'), $community); - $or->findOneBy(array('id' => 884849)) - ->shouldBeCalled() - ->willReturn($place); + $or->findOneBy(['id' => 884849])->shouldBeCalled()->willReturn($place); - $street = new Street($place, 10268); - $street->setName('Księżycowa') - ->setAdditionalName('') - ->setType('ul.'); + $street = new Street($place, 10268, 'ul.', null, 'Księżycowa'); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($street); } function it_converts_node_to_street_entry_with_updating_existing_one( ObjectManager $om, ObjectRepository $or, Street $street - ) { + ): void { $xml = << 02 @@ -79,22 +86,22 @@ function it_converts_node_to_street_entry_with_updating_existing_one( 2013-10-10 EOT; - $place = new Place(884849); - $place->setName('City'); + $community = new Community( + new District(new Province(1, 'województwo'), 1, 'Powiat'), + 1, + 'Gmina', + new CommunityType(1, 'Gmina wiejska') + ); + $place = new Place(884849, 'City', new Type(1, 'wieś'), $community); - $or->findOneBy(array('id' => '0884849')) - ->shouldBeCalled() - ->willReturn($place); + $or->findOneBy(['id' => '0884849'])->shouldBeCalled()->willReturn($place); + $or->findOneBy(['id' => '10268', 'place' => $place])->shouldBeCalled()->willReturn($street); - $or->findOneBy(array('id' => '10268', 'place' => $place)) - ->shouldBeCalled() - ->willReturn($street); + $street->setName('Księżycowa')->shouldBeCalled(); + $street->setAdditionalName(null)->shouldBeCalled(); + $street->setType('ul.')->shouldBeCalled(); - $street->setName('Księżycowa')->shouldBeCalled()->willReturn($street); - $street->setAdditionalName(null)->shouldBeCalled()->willReturn($street); - $street->setType('ul.')->shouldBeCalled()->willReturn($street); - - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($street->getWrappedObject()); } } diff --git a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/TerritorialDivisionNodeConverterSpec.php b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/TerritorialDivisionNodeConverterSpec.php index 5db24d8..e0dfb5c 100644 --- a/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/TerritorialDivisionNodeConverterSpec.php +++ b/spec/FSi/Bundle/TerytDatabaseBundle/Teryt/Import/TerritorialDivisionNodeConverterSpec.php @@ -20,18 +20,19 @@ use FSi\Bundle\TerytDatabaseBundle\Exception\TerritorialDivisionNodeConverterException; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use SimpleXMLElement; class TerritorialDivisionNodeConverterSpec extends ObjectBehavior { - function let(ObjectManager $om, ObjectRepository $or) + function let(ObjectManager $om, ObjectRepository $or): void { // It is not possible to mock internal classes with final constructor - $this->beConstructedWith(new \SimpleXMLElement(''), $om); + $this->beConstructedWith(new SimpleXMLElement(''), $om); $om->getRepository(Argument::type('string'))->willReturn($or); $or->findOneBy(Argument::type('array'))->willReturn(); } - function it_converts_node_to_province(ObjectManager $om, ObjectRepository $or) + function it_converts_node_to_province(ObjectManager $om): void { $xml = << @@ -48,16 +49,16 @@ function it_converts_node_to_province(ObjectManager $om, ObjectRepository $or) EOT; - $expectedProvince = new Province(2); + $expectedProvince = new Province(2, 'województwo'); $expectedProvince->setName('DOLNOŚLĄSKIE'); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($expectedProvince); } function it_converts_node_to_province_with_updating_existing_one( ObjectManager $om, ObjectRepository $or, Province $province - ) { + ): void { $xml = << 02 @@ -76,17 +77,15 @@ function it_converts_node_to_province_with_updating_existing_one( ->shouldBeCalled() ->willReturn($or); - $or->findOneBy(array( - 'code' => 2 - ))->shouldBeCalled()->willReturn($province); + $or->findOneBy(['code' => 2])->shouldBeCalled()->willReturn($province); $province->setName('Dolnośląskie')->shouldBeCalled(); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($province); } - function it_converts_node_to_district(ObjectManager $om, ObjectRepository $or) + function it_converts_node_to_district(ObjectManager $om, ObjectRepository $or): void { $xml = << @@ -101,22 +100,18 @@ function it_converts_node_to_district(ObjectManager $om, ObjectRepository $or) 2013-01-01 EOT; - $province = new Province(2); - $or->findOneBy(array( - 'code' => 2 - ))->shouldBeCalled()->willReturn($province); + $province = new Province(2, 'województwo'); + $or->findOneBy(['code' => 2])->shouldBeCalled()->willReturn($province); - $expectedDistrict = new District(201); - $expectedDistrict->setName('bolesławiecki') - ->setProvince($province); + $expectedDistrict = new District($province, 201, 'bolesławiecki'); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($expectedDistrict); } function it_converts_node_to_district_with_updating_existing_one( ObjectManager $om, ObjectRepository $or, District $district - ) { + ): void { $xml = << 02 @@ -131,23 +126,19 @@ function it_converts_node_to_district_with_updating_existing_one( EOT; - $or->findOneBy(array( - 'code' => 201 - ))->shouldBeCalled()->willReturn($district); + $or->findOneBy(['code' => 201])->shouldBeCalled()->willReturn($district); - $province = new Province(2); - $or->findOneBy(array( - 'code' => 2 - ))->shouldBeCalled()->willReturn($province); + $province = new Province(2, 'województwo'); - $district->setName('bolesławiecki')->shouldBeCalled()->willReturn($district); - $district->setProvince($province)->shouldBeCalled()->willReturn($district); + $or->findOneBy(['code' => 2])->shouldBeCalled()->willReturn($province); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $district->setName('bolesławiecki')->shouldBeCalled(); + + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($district); } - function it_converts_node_to_community(ObjectManager $om, ObjectRepository $or) + function it_converts_node_to_community(ObjectManager $om, ObjectRepository $or): void { $xml = << @@ -160,32 +151,22 @@ function it_converts_node_to_community(ObjectManager $om, ObjectRepository $or) 2013-01-01 EOT; - $district = new District(201); - $district->setName('Bolesławiec'); - - $communityType = new CommunityType(1); - $communityType->setName('gmina miejska'); + $district = new District(new Province(1, 'województwo'), 201, 'Bolesławiec'); - $or->findOneBy(array( - 'code' => 201 - ))->shouldBeCalled()->willReturn($district); + $communityType = new CommunityType(1, 'gmina miejska'); - $or->findOneBy(array( - 'type' => 1 - ))->shouldBeCalled()->willReturn($communityType); + $or->findOneBy(['code' => 201])->shouldBeCalled()->willReturn($district); + $or->findOneBy(['type' => 1])->shouldBeCalled()->willReturn($communityType); - $expectedCommunity = new Community(201011); - $expectedCommunity->setName('Bolesławiec') - ->setType($communityType) - ->setDistrict($district); + $expectedCommunity = new Community($district, 201011, 'Bolesławiec', $communityType); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($expectedCommunity); } function it_converts_node_to_community_with_updating_existing_one( ObjectManager $om, ObjectRepository $or, Community $community - ) { + ): void { $xml = << 02 @@ -197,37 +178,26 @@ function it_converts_node_to_community_with_updating_existing_one( 2013-01-01 EOT; - $district = new District(201); - $district->setName('Bolesławiec'); - - $communityType = new CommunityType(1); - $communityType->setName('gmina miejska'); - - $or->findOneBy(array( - 'code' => 201 - ))->shouldBeCalled()->willReturn($district); + $district = new District(new Province(1, 'województwo'), 201, 'Bolesławiec'); - $or->findOneBy(array( - 'type' => 1 - ))->shouldBeCalled()->willReturn($communityType); + $communityType = new CommunityType(1, 'gmina miejska'); - $or->findOneBy(array( - 'code' => 201011 - ))->shouldBeCalled()->willReturn($community); + $or->findOneBy(['code' => 201])->shouldBeCalled()->willReturn($district); + $or->findOneBy(['type' => 1])->shouldBeCalled()->willReturn($communityType); + $or->findOneBy(['code' => 201011])->shouldBeCalled()->willReturn($community); - $community->setName('Bolesławiec')->shouldBeCalled()->willReturn($community); - $community->setType($communityType)->shouldBeCalled()->willReturn($community); - $community->setDistrict($district)->shouldBeCalled()->willReturn($community); + $community->setName('Bolesławiec')->shouldBeCalled(); + $community->setType($communityType)->shouldBeCalled(); - $this->beConstructedWith(new \SimpleXMLElement($xml), $om); + $this->beConstructedWith(new SimpleXMLElement($xml), $om); $this->convertToEntity()->shouldBeLike($community); } - function it_throws_exception_when_cant_convert_node_to_entity(ObjectManager $om) + function it_throws_exception_when_cant_convert_node_to_entity(ObjectManager $om): void { - $this->beConstructedWith(new \SimpleXMLElement(''), $om); + $this->beConstructedWith(new SimpleXMLElement(''), $om); - $exception = new TerritorialDivisionNodeConverterException(); - $this->shouldThrow($exception)->during('convertToEntity', array()); + $exception = new TerritorialDivisionNodeConverterException('Unknown territory type'); + $this->shouldThrow($exception)->during('convertToEntity', []); } }