Passed
Push — master ( 137960...4d87d9 )
by Sys
11:11
created

Versions::getUrlFromText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
4
namespace TgScraper\Constants;
5
6
7
class Versions
8
{
9
10
    public const V100 = '1.0.0';
11
    public const V110 = '1.1.0';
12
    public const V140 = '1.4.0';
13
    public const V150 = '1.5.0';
14
    public const V160 = '1.6.0';
15
    public const V180 = '1.8.0';
16
    public const V182 = '1.8.2';
17
    public const V183 = '1.8.3';
18
    public const V200 = '2.0.0';
19
    public const V210 = '2.1.0';
20
    public const V211 = '2.1.1';
21
    public const V220 = '2.2.0';
22
    public const V230 = '2.3.0';
23
    public const V231 = '2.3.1';
24
    public const V300 = '3.0.0';
25
    public const V310 = '3.1.0';
26
    public const V320 = '3.2.0';
27
    public const V330 = '3.3.0';
28
    public const V350 = '3.5.0';
29
    public const V360 = '3.6.0';
30
    public const V400 = '4.0.0';
31
    public const V410 = '4.1.0';
32
    public const V420 = '4.2.0';
33
    public const V430 = '4.3.0';
34
    public const V440 = '4.4.0';
35
    public const V450 = '4.5.0';
36
    public const V460 = '4.6.0';
37
    public const V470 = '4.7.0';
38
    public const V480 = '4.8.0';
39
    public const V490 = '4.9.0';
40
    public const V500 = '5.0.0';
41
    public const V510 = '5.1.0';
42
    public const V520 = '5.2.0';
43
    public const V530 = '5.3.0';
44
    public const LATEST = 'latest';
45
    public const STABLE = self::V530;
46
47
    public const URLS = [
48
        self::V100 => 'https://web.archive.org/web/20150714025308id_/https://core.telegram.org/bots/api/',
49
        self::V110 => 'https://web.archive.org/web/20150812125616id_/https://core.telegram.org/bots/api',
50
        self::V140 => 'https://web.archive.org/web/20150909214252id_/https://core.telegram.org/bots/api',
51
        self::V150 => 'https://web.archive.org/web/20150921091215id_/https://core.telegram.org/bots/api/',
52
        self::V160 => 'https://web.archive.org/web/20151023071257id_/https://core.telegram.org/bots/api',
53
        self::V180 => 'https://web.archive.org/web/20160112101045id_/https://core.telegram.org/bots/api',
54
        self::V182 => 'https://web.archive.org/web/20160126005312id_/https://core.telegram.org/bots/api',
55
        self::V183 => 'https://web.archive.org/web/20160305132243id_/https://core.telegram.org/bots/api',
56
        self::V200 => 'https://web.archive.org/web/20160413101342id_/https://core.telegram.org/bots/api',
57
        self::V210 => 'https://web.archive.org/web/20160912130321id_/https://core.telegram.org/bots/api',
58
        self::V211 => 'https://web.archive.org/web/20160912130321id_/https://core.telegram.org/bots/api',
59
        self::V220 => 'https://web.archive.org/web/20161004150232id_/https://core.telegram.org/bots/api',
60
        self::V230 => 'https://web.archive.org/web/20161124162115id_/https://core.telegram.org/bots/api',
61
        self::V231 => 'https://web.archive.org/web/20161204181811id_/https://core.telegram.org/bots/api',
62
        self::V300 => 'https://web.archive.org/web/20170612094628id_/https://core.telegram.org/bots/api',
63
        self::V310 => 'https://web.archive.org/web/20170703123052id_/https://core.telegram.org/bots/api',
64
        self::V320 => 'https://web.archive.org/web/20170819054238id_/https://core.telegram.org/bots/api',
65
        self::V330 => 'https://web.archive.org/web/20170914060628id_/https://core.telegram.org/bots/api',
66
        self::V350 => 'https://web.archive.org/web/20171201065426id_/https://core.telegram.org/bots/api',
67
        self::V360 => 'https://web.archive.org/web/20180217001114id_/https://core.telegram.org/bots/api',
68
        self::V400 => 'https://web.archive.org/web/20180728174553id_/https://core.telegram.org/bots/api',
69
        self::V410 => 'https://web.archive.org/web/20180828155646id_/https://core.telegram.org/bots/api',
70
        self::V420 => 'https://web.archive.org/web/20190417160652id_/https://core.telegram.org/bots/api',
71
        self::V430 => 'https://web.archive.org/web/20190601122107id_/https://core.telegram.org/bots/api',
72
        self::V440 => 'https://web.archive.org/web/20190731114703id_/https://core.telegram.org/bots/api',
73
        self::V450 => 'https://web.archive.org/web/20200107090812id_/https://core.telegram.org/bots/api',
74
        self::V460 => 'https://web.archive.org/web/20200208225346id_/https://core.telegram.org/bots/api',
75
        self::V470 => 'https://web.archive.org/web/20200401052001id_/https://core.telegram.org/bots/api',
76
        self::V480 => 'https://web.archive.org/web/20200429054924id_/https://core.telegram.org/bots/api',
77
        self::V490 => 'https://web.archive.org/web/20200611131321id_/https://core.telegram.org/bots/api',
78
        self::V500 => 'https://web.archive.org/web/20201104151640id_/https://core.telegram.org/bots/api',
79
        self::V510 => 'https://web.archive.org/web/20210315055600id_/https://core.telegram.org/bots/api',
80
        self::V520 => 'https://web.archive.org/web/20210428195636id_/https://core.telegram.org/bots/api',
81
        self::V530 => 'https://web.archive.org/web/20210626142851id_/https://core.telegram.org/bots/api',
82
        self::LATEST => 'https://core.telegram.org/bots/api'
83
    ];
84
85
    public static function getVersionFromText(string $text): string
86
    {
87
        $text = str_replace(['.', 'v'], ['', ''], strtolower($text));
88
        $const = sprintf('%s::V%s', self::class, $text);
89
        if (defined($const)) {
90
            return constant($const);
91
        }
92
        return self::LATEST;
93
    }
94
95
    public static function getUrlFromText(string $text): string
96
    {
97
        $version = self::getVersionFromText($text);
98
        return self::URLS[$version] ?? self::URLS[self::LATEST];
99
    }
100
101
}