Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
3 / 6
25.00% covered (danger)
25.00%
1 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Postcode_Location
50.00% covered (danger)
50.00%
3 / 6
25.00% covered (danger)
25.00%
1 / 4
6.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get_postcode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_state
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_city
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * A single location in a postcode (there can be many).
4 *
5 * @package brianhenryie/bh-wc-postcode-address-autofill
6 */
7
8namespace BrianHenryIE\WC_Postcode_Address_Autofill\API;
9
10use stdClass;
11
12/**
13 * Plain old object. Construct from JSON object array entry in data dir.
14 */
15class Postcode_Location {
16
17    /**
18     * Full or partial postcode for this area.
19     */
20    protected string $postcode;
21
22    /**
23     * The state.
24     */
25    protected string $state;
26
27    /**
28     * The city.
29     */
30    protected string $city;
31
32    /**
33     * Constructor
34     *
35     * @param stdClass $json JSON sub-field from `/data/` directory.
36     */
37    public function __construct( stdClass $json ) {
38        $this->postcode = $json->postcode;
39        $this->state    = $json->state;
40        $this->city     = $json->city;
41    }
42
43    /**
44     * Get the postcode (may be full or partial) that matches this location.
45     */
46    public function get_postcode(): string {
47        return $this->postcode;
48    }
49
50    /**
51     * Get the state.
52     */
53    public function get_state(): string {
54        return $this->state;
55    }
56
57    /**
58     * Get the city.
59     */
60    public function get_city(): string {
61        return $this->city;
62    }
63}