HasHttpsImage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B ensureHttps() 0 16 5
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