address: render lines: code style fixed

This commit is contained in:
nobohan 2022-01-06 11:55:32 +01:00
parent 077317c2bf
commit 4c4a003977

View File

@ -39,6 +39,24 @@ class AddressRender implements ChillEntityRenderInterface
/**
* @param Address addr
* @param mixed $addr
*/
public function renderBox($addr, array $options): string
{
$options = array_merge(self::DEFAULT_OPTIONS, $options);
return $this->templating
->render('@ChillMain/Entity/address.html.twig', [
'address' => $addr,
'streetLine' => $this->renderStreetLine($addr),
'render' => $options['render'] ?? 'bloc',
'options' => $options,
]);
}
/**
* @param Address addr
* @param mixed $addr
*
* @return string[]
*/
public function renderLines($addr): array
@ -65,24 +83,6 @@ class AddressRender implements ChillEntityRenderInterface
return $lines;
}
/**
* @param Address addr
* @param mixed $addr
*/
public function renderBox($addr, array $options): string
{
$options = array_merge(self::DEFAULT_OPTIONS, $options);
return $this->templating
->render('@ChillMain/Entity/address.html.twig', [
'address' => $addr,
'streetLine' => $this->renderStreetLine($addr),
'render' => $options['render'] ?? 'bloc',
'options' => $options,
]);
}
/**
* @param Address addr
* @param mixed $addr
@ -97,6 +97,80 @@ class AddressRender implements ChillEntityRenderInterface
return $entity instanceof Address;
}
private function renderBuildingLine($addr): ?string
{
$res = $addr->getBuildingName() . ' - ' . $this->renderIntraBuildingLine($addr);
if (null === $addr->getBuildingName()) {
$res = $this->renderIntraBuildingLine($addr);
if (null === $this->renderIntraBuildingLine($addr)) {
return null;
}
}
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$res = $addr->getBuildingName();
}
}
return $res;
}
private function renderCityLine($addr): string
{
if (!empty($addr->getPostcode())) {
$res = strtr('{postcode} {label}', [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName(),
]);
}
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
if ($addr->getDistribution()) {
$res = $res . $addr->getDistribution();
}
}
}
return $res;
}
private function renderCountryLine($addr): ?string
{
return $addr->getPostCode()->getCountry()->getName();
}
private function renderDeliveryLine($addr): ?string
{
return $addr->getExtra();
}
private function renderIntraBuildingLine($addr): ?string
{
$arr = [];
if ($addr->getFlat()) {
$arr[] = $addr->getFlat();
}
if ($addr->getFloor()) {
$arr[] = $addr->getFloor();
}
if ($addr->getSteps()) {
$arr[] = $addr->getSteps();
}
if ($addr->getCorridor()) {
$arr[] = $addr->getCorridor();
}
return implode(' - ', $arr);
}
private function renderStreetLine($addr): string
{
if (!empty($addr->getStreet())) {
@ -125,70 +199,4 @@ class AddressRender implements ChillEntityRenderInterface
return $res;
}
private function renderCityLine($addr): string
{
if (!empty($addr->getPostcode())) {
$res = strtr('{postcode} {label}', [
'{postcode}' => $addr->getPostcode()->getCode(),
'{label}' => $addr->getPostcode()->getName(),
]);
}
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
if ($addr->getDistribution()) {
$res = $res.$addr->getDistribution();
}
}
}
return $res;
}
private function renderCountryLine($addr): ?string
{
return $addr->getPostCode()->getCountry()->getName();
}
private function renderDeliveryLine($addr): ?string
{
return $addr->getExtra();
}
private function renderBuildingLine($addr): ?string
{
$res = $addr->getBuildingName() . ' - ' . $this->renderIntraBuildingLine($addr);
if (null === $addr->getBuildingName()) {
$res = $this->renderIntraBuildingLine($addr);
if (null === $this->renderIntraBuildingLine($addr)) {
return null;
}
}
if (null !== $addr->getPostCode()->getCountry()->getCountryCode()) {
if ($addr->getPostCode()->getCountry()->getCountryCode() === 'FR') {
$res = $addr->getBuildingName();
}
}
return $res;
}
private function renderIntraBuildingLine($addr): ?string
{
$arr = [];
if ($addr->getFlat()) {
array_push($arr, $addr->getFlat());
}
if ($addr->getFloor()) {
array_push($arr, $addr->getFloor());
}
if ($addr->getSteps()) {
array_push($arr, $addr->getSteps());
}
if ($addr->getCorridor()) {
array_push($arr, $addr->getCorridor());
}
return join(' - ', $arr);
}
}