-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMunicipalityCodeSource.php
More file actions
52 lines (49 loc) · 1.73 KB
/
Copy pathMunicipalityCodeSource.php
File metadata and controls
52 lines (49 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**
* Italix Rules - MunicipalityCodeSource
*
* @package Italix\Rules
* @license MPL-2.0
*/
declare(strict_types=1);
namespace Italix\Rules;
/**
* Optional reference data for TaxCodeCheck: does this place-of-birth code
* exist? (Italy: the four-character "codice Belfiore", e.g. H501 for Rome.)
*
* The library ships no such table on purpose. It is large, it changes when
* municipalities merge, and every application that needs it already has it
* in its own database — italix/rules would only offer a second, staler copy.
*
* So the check states its need as one method and the application satisfies it:
*
* final class DbMunicipalityCodes implements MunicipalityCodeSource
* {
* public function __construct(private DataManager $dm) {}
*
* public function has_code(string $code_c, string $country_c = 'IT'): bool
* {
* return $this->dm->query_one(
* 'SELECT 1 FROM uni_municipality_it WHERE belfiore_c = ?', [$code_c]
* ) !== null;
* }
* }
*
* Without a source, TaxCodeCheck still verifies length, character set and the
* control character — it just cannot rule out a well-formed code for a place
* that does not exist.
*/
interface MunicipalityCodeSource
{
/**
* @param string $code_c The place code as it appears inside the tax code
* @param string $country_c ISO 3166-1 alpha-2 country the code belongs to
* @return bool
*/
public function has_code(string $code_c, string $country_c = 'IT'): bool;
}