Skip to content

Commit

Permalink
Update Istat data (#10)
Browse files Browse the repository at this point in the history
* Update Istat data

* Revert to correct Municipality fiscal code regex

Istat resolved my ticket 00017276

* Fiscal code of every Municipality is now available

Istat resolved my ticket 00017261

---------

Co-authored-by: mlocati <mlocati@users.noreply.github.com>
Co-authored-by: Michele Locati <michele@locati.it>
  • Loading branch information
3 people authored Jul 3, 2024
1 parent 2955f1a commit 28ca0cc
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 27 deletions.
11 changes: 2 additions & 9 deletions src/Build/Municipality.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ public function __construct(
$this->isRegionalCapital = $data->CC_REG === 1;
$this->isProvinceCapital = $data->CC_UTS === 1;
$this->cadastralCode = $data->COD_CATASTO;
$fiscalCode = ltrim((string) $data->COD_COM_FISCALE, '0');
$len = strlen($fiscalCode);
if ($len > 0 && $len < 11) {
$fiscalCode = str_pad($fiscalCode, 11, '0', STR_PAD_LEFT);
}
$this->fiscalCode = $fiscalCode;
$this->fiscalCode = str_pad((string) $data->COD_COM_FISCALE, 11, '0', STR_PAD_LEFT);
$this->nuts1 = $data->COM_NUTS1_2024;
$this->nuts2 = $data->COM_NUTS2_2024;
$this->nuts3 = $data->COM_NUTS3_2024;
Expand Down Expand Up @@ -94,9 +89,7 @@ public function serialize(Collator $collator): array
$result['isProvinceCapital'] = true;
}
$result['cadastralCode'] = $this->cadastralCode;
if ($this->fiscalCode !== '') {
$result['fiscalCode'] = $this->fiscalCode;
}
$result['fiscalCode'] = $this->fiscalCode;
if ($this->nuts1 !== $this->province->region->geographicalSubdivision->nuts1) {
$result['nuts1'] = $this->nuts1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build/data/schema-61.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
},
"COD_COM_FISCALE": {
"type": ["integer", "string", "null"],
"pattern": "^0?[0-9]{11}$",
"pattern": "^[0-9]{11}$",
"minimum": 1,
"maximum": 99999999999
},
Expand Down
2 changes: 1 addition & 1 deletion src/Municipality.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getCadastralCode(): string
*/
public function getFiscalCode(): string
{
return $this->data['fiscalCode'] ?? '';
return $this->data['fiscalCode'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/data/geographical-subdivisions.php

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/data/geographical-subdivisions.unminified.php
Original file line number Diff line number Diff line change
Expand Up @@ -5011,6 +5011,7 @@
'id' => '256',
'name' => 'Uggiate con Ronago',
'cadastralCode' => 'M435',
'fiscalCode' => '04137960136',
],
[
'id' => '233',
Expand Down Expand Up @@ -24257,6 +24258,7 @@
'id' => '075',
'name' => 'Setteville',
'cadastralCode' => 'M437',
'fiscalCode' => '91021680250',
],
[
'id' => '056',
Expand Down Expand Up @@ -24819,6 +24821,7 @@
'id' => '108',
'name' => 'Santa Caterina d\'Este',
'cadastralCode' => 'M438',
'fiscalCode' => '05598790284',
],
[
'id' => '080',
Expand Down Expand Up @@ -27280,6 +27283,7 @@
'id' => '128',
'name' => 'Sovizzo',
'cadastralCode' => 'M436',
'fiscalCode' => '04506950247',
],
[
'id' => '104',
Expand Down
12 changes: 1 addition & 11 deletions test/tests/PropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,7 @@ public function testMunicipalityProperties(Municipality $municipality): void
$this->assertIsBool($municipality->isRegionalCapital());
$this->assertIsBool($municipality->isProvinceCapital());
$this->assertMatchesRegularExpression('/^[A-Z][0-9]{3}$/', $municipality->getCadastralCode());
switch ($municipality->getID()) {
case '028108': // Santa Caterina d'Este (PD)
case '025075': // Setteville (BL)
case '024128': // Sovizzo (VI)
case '013256': // Uggiate con Ronago (CO)
$optional = true;
break;
default:
$optional = false;
}
self::testFiscalCode($municipality->getFiscalCode(), $optional, "{$municipality->getID()} {$municipality}");
self::testFiscalCode($municipality->getFiscalCode(), false, "{$municipality->getID()} {$municipality}");
$this->assertMatchesRegularExpression('/^IT[A-Z]$/', $municipality->getNuts1());
$this->assertMatchesRegularExpression('/^IT[A-Z][0-9]$/', $municipality->getNuts2());
$this->assertMatchesRegularExpression('/^IT[A-Z][0-9][0-9A-Z]$/', $municipality->getNuts3());
Expand Down
4 changes: 0 additions & 4 deletions test/tests/UniqueKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public function provideMunicipalityCases(): array
['getID'],
['getCadastralCode'],
['getFiscalCode', [
'028108', // Santa Caterina d'Este (PD)
'025075', // Setteville (BL)
'024128', // Sovizzo (VI)
'013256', // Uggiate con Ronago (CO)
]],
['__toString'],
];
Expand Down

0 comments on commit 28ca0cc

Please sign in to comment.