1 | <?php |
||
17 | class UrlShortener implements UrlShortenerInterface |
||
18 | { |
||
19 | use TagManagerTrait; |
||
20 | |||
21 | const DEFAULT_CHARS = '123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ'; |
||
22 | |||
23 | /** |
||
24 | * @var ClientInterface |
||
25 | */ |
||
26 | private $httpClient; |
||
27 | /** |
||
28 | * @var EntityManagerInterface |
||
29 | */ |
||
30 | private $em; |
||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $chars; |
||
35 | /** |
||
36 | * @var Cache |
||
37 | */ |
||
38 | private $cache; |
||
39 | /** |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $isUrlExistsValidation; |
||
43 | |||
44 | /** |
||
45 | * UrlShortener constructor. |
||
46 | * @param ClientInterface $httpClient |
||
47 | * @param EntityManagerInterface $em |
||
48 | * @param Cache $cache |
||
49 | * @param bool $isUrlExistsValidation |
||
50 | * @param string $chars |
||
51 | * |
||
52 | * @Inject({ |
||
53 | * "httpClient", |
||
54 | * "em", |
||
55 | * Cache::class, |
||
56 | * "config.url_shortener.validate_url", |
||
57 | * "config.url_shortener.shortcode_chars" |
||
58 | * }) |
||
59 | */ |
||
60 | 7 | public function __construct( |
|
61 | ClientInterface $httpClient, |
||
62 | EntityManagerInterface $em, |
||
63 | Cache $cache, |
||
64 | $isUrlExistsValidation, |
||
65 | $chars = self::DEFAULT_CHARS |
||
66 | ) { |
||
67 | 7 | $this->httpClient = $httpClient; |
|
68 | 7 | $this->em = $em; |
|
69 | 7 | $this->chars = empty($chars) ? self::DEFAULT_CHARS : $chars; |
|
70 | 7 | $this->cache = $cache; |
|
71 | 7 | $this->isUrlExistsValidation = $isUrlExistsValidation; |
|
72 | 7 | } |
|
73 | |||
74 | /** |
||
75 | * Creates and persists a unique shortcode generated for provided url |
||
76 | * |
||
77 | * @param UriInterface $url |
||
78 | * @param string[] $tags |
||
79 | * @return string |
||
80 | * @throws InvalidUrlException |
||
81 | * @throws RuntimeException |
||
82 | */ |
||
83 | 4 | public function urlToShortCode(UriInterface $url, array $tags = []) |
|
126 | |||
127 | /** |
||
128 | * Tries to perform a GET request to provided url, returning true on success and false on failure |
||
129 | * |
||
130 | * @param UriInterface $url |
||
131 | * @return bool |
||
132 | */ |
||
133 | 1 | protected function checkUrlExists(UriInterface $url) |
|
143 | |||
144 | /** |
||
145 | * Generates the unique shortcode for an autoincrement ID |
||
146 | * |
||
147 | * @param int $id |
||
148 | * @return string |
||
149 | */ |
||
150 | 1 | protected function convertAutoincrementIdToShortCode($id) |
|
164 | |||
165 | /** |
||
166 | * Tries to find the mapped URL for provided short code. Returns null if not found |
||
167 | * |
||
168 | * @param string $shortCode |
||
169 | * @return string|null |
||
170 | * @throws InvalidShortCodeException |
||
171 | */ |
||
172 | 3 | public function shortCodeToUrl($shortCode) |
|
198 | } |
||
199 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: