Skip to content

Commit

Permalink
apply sonar feedback #1977
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinx13 committed Jan 17, 2024
1 parent 9ef2122 commit a27652a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public function __construct(

public function supports(Affectation $affectation): bool
{
$partner = $affectation->getPartner();

return $this->isEsaboraPartnerActive($affectation)
&& PartnerType::COMMUNE_SCHS === $affectation->getPartner()->getType();
}
Expand Down
44 changes: 29 additions & 15 deletions src/Factory/Interconnection/Esabora/DossierMessageSISHFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Entity\Suivi;
use App\Messenger\Message\Esabora\DossierMessageSISH;
use App\Repository\SuiviRepository;
use App\Service\DataGouv\AddressService;
use App\Service\Esabora\AbstractEsaboraService;
use App\Service\Esabora\Enum\PersonneType;
use App\Service\Esabora\Model\DossierMessageSISHPersonne;
Expand All @@ -30,15 +29,12 @@ public function __construct(
private readonly UploadHandlerService $uploadHandlerService,
private readonly ParameterBagInterface $parameterBag,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly AddressService $addressService,
) {
parent::__construct($this->uploadHandlerService);
}

public function supports(Affectation $affectation): bool
{
$partner = $affectation->getPartner();

return $this->isEsaboraPartnerActive($affectation)
&& PartnerType::ARS === $affectation->getPartner()->getType();
}
Expand Down Expand Up @@ -70,13 +66,21 @@ public function createInstance(Affectation $affectation): DossierMessageSISH
: null;

$etage = $signalement->getEtageOccupant() ? EtageParser::parse($signalement->getEtageOccupant()) : null;
$escalier = $signalement->getEscalierOccupant() ? EscalierParser::parse($signalement->getEscalierOccupant()) : null;
$numPorte = $signalement->getNumAppartOccupant() ? substr($signalement->getNumAppartOccupant(), 0, 30) : null;
$escalier = $signalement->getEscalierOccupant()
? EscalierParser::parse($signalement->getEscalierOccupant())
: null;
$numPorte = $signalement->getNumAppartOccupant()
? substr($signalement->getNumAppartOccupant(), 0, 30)
: null;
$villeOccupant = $signalement->getVilleOccupant() ? substr($signalement->getVilleOccupant(), 0, 60) : null;
$numeroInvariant = $signalement->getNumeroInvariant() ? substr($signalement->getNumeroInvariant(), 0, 12) : null;
$typeEnergieLogement = $signalement->getTypeEnergieLogement() ? substr($signalement->getTypeEnergieLogement(), 0, 30) : null;
$codeInsee = $signalement->getInseeOccupant() ?: $this->addressService->getCodeInsee($signalement->getAdresseOccupant().' '.$signalement->getCpOccupant().' '.$signalement->getVilleOccupant());
$codeInsee = $codeInsee ? substr($codeInsee, 0, 5) : null;
$numeroInvariant = $signalement->getNumeroInvariant()
? substr($signalement->getNumeroInvariant(), 0, 12)
: null;
$typeEnergieLogement = $signalement->getTypeEnergieLogement()
? substr($signalement->getTypeEnergieLogement(), 0, 30)
: null;

$codeInsee = $signalement->getInseeOccupant() ? substr($signalement->getInseeOccupant(), 0, 5) : null;

return (new DossierMessageSISH())
->setUrl($partner->getEsaboraUrl())
Expand Down Expand Up @@ -151,7 +155,9 @@ public function createDossierPersonne(
): ?DossierMessageSISHPersonne {
if (PersonneType::OCCUPANT === $personneType) {
$prenom = $signalement->getPrenomOccupant() ? substr($signalement->getPrenomOccupant(), 0, 30) : null;
$tel = $signalement->getTelOccupantDecoded(true) ? substr($signalement->getTelOccupantDecoded(true), 0, 20) : null;
$tel = $signalement->getTelOccupantDecoded(true)
? substr($signalement->getTelOccupantDecoded(true), 0, 20)
: null;

return (new DossierMessageSISHPersonne())
->setType(PersonneType::OCCUPANT->value)
Expand All @@ -162,7 +168,9 @@ public function createDossierPersonne(
}

if (PersonneType::PROPRIETAIRE === $personneType && !empty($signalement->getNomProprio())) {
$tel = $signalement->getTelProprioDecoded(true) ? substr($signalement->getTelProprioDecoded(true), 0, 20) : null;
$tel = $signalement->getTelProprioDecoded(true)
? substr($signalement->getTelProprioDecoded(true), 0, 20)
: null;

return (new DossierMessageSISHPersonne())
->setType(PersonneType::PROPRIETAIRE->value)
Expand All @@ -174,9 +182,15 @@ public function createDossierPersonne(

if (PersonneType::DECLARANT === $personneType && !empty($signalement->getLienDeclarantOccupant())) {
$prenom = $signalement->getPrenomDeclarant() ? substr($signalement->getPrenomDeclarant(), 0, 30) : null;
$tel = $signalement->getTelDeclarantDecoded(true) ? substr($signalement->getTelDeclarantDecoded(true), 0, 20) : null;
$structure = $signalement->getStructureDeclarant() ? substr($signalement->getStructureDeclarant(), 0, 150) : null;
$lienOccupant = $signalement->getLienDeclarantOccupant() ? substr($signalement->getLienDeclarantOccupant(), 0, 150) : null;
$tel = $signalement->getTelDeclarantDecoded(true)
? substr($signalement->getTelDeclarantDecoded(true), 0, 20)
: null;
$structure = $signalement->getStructureDeclarant()
? substr($signalement->getStructureDeclarant(), 0, 150)
: null;
$lienOccupant = $signalement->getLienDeclarantOccupant()
? substr($signalement->getLienDeclarantOccupant(), 0, 150)
: null;

return (new DossierMessageSISHPersonne())
->setType(PersonneType::DECLARANT->value)
Expand Down
13 changes: 10 additions & 3 deletions tests/Functional/Factory/Oilhi/DossierMessageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ public function testDossierMessageFullyCreated(string $reference): void
$this->assertNotEmpty($dossierMessage->getDesordresCritere());
$this->assertNotEmpty($dossierMessage->getDesordresPrecision());

$this->assertMatchesRegularExpression(self::PATTERN_EXPECTED_DATE_FORMAT, $dossierMessage->getDateDepotSignalement());
$this->assertMatchesRegularExpression(self::PATTERN_EXPECTED_DATE_FORMAT, $dossierMessage->getDateAffectationSignalement());
$this->assertMatchesRegularExpression(self::PATTERN_EXPECTED_DATE_FORMAT, $dossierMessage->getDateVisite());
$this->assertMatchesRegularExpression(
self::PATTERN_EXPECTED_DATE_FORMAT,
$dossierMessage->getDateDepotSignalement());
$this->assertMatchesRegularExpression(
self::PATTERN_EXPECTED_DATE_FORMAT,
$dossierMessage->getDateAffectationSignalement());
$this->assertMatchesRegularExpression(
self::PATTERN_EXPECTED_DATE_FORMAT,
$dossierMessage->getDateVisite()
);

$this->assertCount(2, explode(',', $dossierMessage->getCourrielContributeurs()));
}
Expand Down
8 changes: 0 additions & 8 deletions tests/Unit/Factory/Esabora/DossierMessageSISHFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Entity\Enum\PartnerType;
use App\Factory\Interconnection\Esabora\DossierMessageSISHFactory;
use App\Repository\SuiviRepository;
use App\Service\DataGouv\AddressService;
use App\Service\Esabora\AbstractEsaboraService;
use App\Service\UploadHandlerService;
use App\Tests\FixturesHelper;
Expand Down Expand Up @@ -48,18 +47,11 @@ public function testDossierMessageFactoryIsFullyCreated()
->with('back_signalement_view')
->willReturn('/bo/signalements/00000000-0000-0000-2022-000000000001');

$addressService = $this->createMock(AddressService::class);
$addressService
->expects($this->once())
->method('getCodeInsee')
->willReturn($signalement->getInseeOccupant());

$dossierMessageFactory = new DossierMessageSISHFactory(
$suiviRepositoryMock,
$uploadHandlerServiceMock,
$parameterBagMock,
$urlGeneratorMock,
$addressService
);

$signalement->setNumAppartOccupant('à gauche de l\'entrée principale, appart 11');
Expand Down
6 changes: 0 additions & 6 deletions tests/Unit/Service/DataGouv/AddressServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ protected function setUp(): void
$this->addressService = new AddressService($mockHttpClient, $this->createMock(LoggerInterface::class));
}

public function testGetCodeInsee(): void
{
$codeInsee = $this->addressService->getCodeInsee(self::ADDRESS);
$this->assertEquals('44179', $codeInsee);
}

public function testSearchAddress(): void
{
$addresses = $this->addressService->searchAddress(self::ADDRESS);
Expand Down

0 comments on commit a27652a

Please sign in to comment.