Completed
Push — add/gdpr-ads-compliance ( 47ea51...6d1e7f )
by
unknown
09:08
created

Metadata   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A __get() 0 4 1
1
<?php
2
3
namespace MaxMind\Db\Reader;
4
5
/**
6
 * This class provides the metadata for the MaxMind DB file.
7
 *
8
 * @property int nodeCount This is an unsigned 32-bit integer indicating
9
 * the number of nodes in the search tree.
10
 * @property int recordSize This is an unsigned 16-bit integer. It
11
 * indicates the number of bits in a record in the search tree. Note that each
12
 * node consists of two records.
13
 * @property int ipVersion This is an unsigned 16-bit integer which is
14
 * always 4 or 6. It indicates whether the database contains IPv4 or IPv6
15
 * address data.
16
 * @property string databaseType This is a string that indicates the structure
17
 * of each data record associated with an IP address. The actual definition of
18
 * these structures is left up to the database creator.
19
 * @property array languages An array of strings, each of which is a language
20
 * code. A given record may contain data items that have been localized to
21
 * some or all of these languages. This may be undefined.
22
 * @property int binaryFormatMajorVersion This is an unsigned 16-bit
23
 * integer indicating the major version number for the database's binary
24
 * format.
25
 * @property int binaryFormatMinorVersion This is an unsigned 16-bit
26
 * integer indicating the minor version number for the database's binary format.
27
 * @property int buildEpoch This is an unsigned 64-bit integer that
28
 * contains the database build timestamp as a Unix epoch value.
29
 * @property array description This key will always point to a map
30
 * (associative array). The keys of that map will be language codes, and the
31
 * values will be a description in that language as a UTF-8 string. May be
32
 * undefined for some databases.
33
 */
34
class Metadata
35
{
36
    private $binaryFormatMajorVersion;
37
    private $binaryFormatMinorVersion;
38
    private $buildEpoch;
39
    private $databaseType;
40
    private $description;
41
    private $ipVersion;
42
    private $languages;
43
    private $nodeByteSize;
44
    private $nodeCount;
45
    private $recordSize;
46
    private $searchTreeSize;
47
48
    public function __construct($metadata)
49
    {
50
        $this->binaryFormatMajorVersion =
51
            $metadata['binary_format_major_version'];
52
        $this->binaryFormatMinorVersion =
53
            $metadata['binary_format_minor_version'];
54
        $this->buildEpoch = $metadata['build_epoch'];
55
        $this->databaseType = $metadata['database_type'];
56
        $this->languages = $metadata['languages'];
57
        $this->description = $metadata['description'];
58
        $this->ipVersion = $metadata['ip_version'];
59
        $this->nodeCount = $metadata['node_count'];
60
        $this->recordSize = $metadata['record_size'];
61
        $this->nodeByteSize = $this->recordSize / 4;
62
        $this->searchTreeSize = $this->nodeCount * $this->nodeByteSize;
63
    }
64
65
    public function __get($var)
66
    {
67
        return $this->$var;
68
    }
69
}
70