DevGoogleImageTaggingService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 11
c 4
b 0
f 0
dl 0
loc 34
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getImageToSend() 0 24 2
1
<?php
2
3
namespace App\Service;
4
5
use App\Entity\Image;
6
use Exception;
7
8
class DevGoogleImageTaggingService extends GoogleImageTaggingService implements ImageTaggingServiceInterface
9
{
10
    /**
11
     * Unlike production, our dev service grabs the actual image data from
12
     * our local URL and throws it at Google directly, because its URLs
13
     * aren't public. We don't read off the filesystem because filesystem
14
     * storage is just one option in Liip Imagine (or even Vich uploader.)
15
     *
16
     * @return resource|bool
17
     */
18
    protected function getImageToSend(Image $image)
19
    {
20
        $url = $image->getMediumImageUri();
21
        if ($url === null) {
0 ignored issues
show
introduced by
The condition $url === null is always false.
Loading history...
22
            throw new Exception("Couldn't get image URL in image tagger.");
23
        }
24
25
        $opts=array(
26
            // Our staging server doesn't trust itself! TODO: We're not using
27
            // Vagrant for staging any more. Maybe we don't need this. Plus we
28
            // should just make the server certificates work.
29
            "ssl" => array(
30
                "verify_peer"=>false,
31
                "verify_peer_name"=>false,
32
            ),
33
            // And on dev, we want to use the Symfony local server proxy
34
            // (our Mac is set up to see the proxy config on http://127.0.0.1:7080/proxy.pac
35
            // but we'll just hardcode it here. Hopefully it doesn't change!)
36
            "http" => [
37
                'proxy' => 'tcp://localhost:7080'
38
            ]
39
        );
40
41
        return fopen($url, 'rb', false, stream_context_create($opts));
42
    }
43
}
44