HasHttpsImage::ensureHttps()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace Notimatica\Driver\Support;
4
5
trait HasHttpsImage
6
{
7
    /**
8
     * Ensure image is https.
9
     *
10
     * @param  string $image
11
     * @return string
12
     */
13
    public function ensureHttps($image)
14
    {
15
        if (! $image) {
16
            return;
17
        }
18
19
        $parsed = parse_url($image);
20
21
        if ($parsed['scheme'] == 'https' ||
22
            $parsed['scheme'] == 'ssl'   ||
23
            preg_match('/192\.168|localhost|images\.weserv\.nl/', $parsed['host'])) {
24
            return $image;
25
        }
26
27
        return 'https://images.weserv.nl/?url=' . str_replace('http://', '', $image);
28
    }
29
}
30