Completed
Push — master ( 8d91fd...0e0bf2 )
by Benjamin
11:32
created
DataFixtures/ORM/MediaProvider.php 2 patches
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -88,6 +88,9 @@  discard block
 block discarded – undo
88 88
         return $url;
89 89
     }
90 90
 
91
+    /**
92
+     * @param string $url
93
+     */
91 94
     protected function downloadMedia($url, $ext)
92 95
     {
93 96
         $filepath = sys_get_temp_dir() . '/' . uniqid() . '.' . $ext;
@@ -102,6 +105,9 @@  discard block
 block discarded – undo
102 105
         return new File($filepath, 'random');
103 106
     }
104 107
 
108
+    /**
109
+     * @param string $key
110
+     */
105 111
     protected function fetchFromCache($key)
106 112
     {
107 113
         $fs = new Filesystem();
@@ -130,6 +136,9 @@  discard block
 block discarded – undo
130 136
         }
131 137
     }
132 138
 
139
+    /**
140
+     * @param string $key
141
+     */
133 142
     protected function storeInCache($key, File $file)
134 143
     {
135 144
         $fs = new Filesystem();
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@  discard block
 block discarded – undo
27 27
     {
28 28
         do {
29 29
             $dimensions = $this->fetchDimensions($width, $height);
30
-            $file = $this->fetchFromCache($dimensions['w'] . '-' . $dimensions['h']);
30
+            $file = $this->fetchFromCache($dimensions['w'].'-'.$dimensions['h']);
31 31
             if ($file === null) {
32 32
                 $file = $this->downloadMedia($this->generateUrl($dimensions, $type), 'jpg');
33
-                $this->storeInCache($dimensions['w'] . '-' . $dimensions['h'], $file);
33
+                $this->storeInCache($dimensions['w'].'-'.$dimensions['h'], $file);
34 34
             }
35 35
         } while (!preg_match('@^image/@', $file->getMimeType()));
36 36
 
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
     public function randomFile($fileType)
43 43
     {
44
-        $file = $this->fetchFromCache("file-" . $fileType);
44
+        $file = $this->fetchFromCache("file-".$fileType);
45 45
         if ($file === null) {
46 46
             switch ($fileType) {
47 47
                 case "pdf":
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
                     break;
51 51
             }
52 52
         }
53
-        $this->storeInCache("file-" . $fileType, $file);
53
+        $this->storeInCache("file-".$fileType, $file);
54 54
         $media = $this->mediaManager->upload($file);
55 55
 
56 56
         return $media;
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
             $url .= 'g/';
81 81
         }
82 82
 
83
-        $url .= $dimensions['w'] . '/' . $dimensions['h'];
83
+        $url .= $dimensions['w'].'/'.$dimensions['h'];
84 84
 
85 85
         $category = ['abstract', 'city', 'nature', 'moutains'];
86
-        $url .= '/' . $category[array_rand($category, 1)] . '/';
86
+        $url .= '/'.$category[array_rand($category, 1)].'/';
87 87
 
88 88
         return $url;
89 89
     }
90 90
 
91 91
     protected function downloadMedia($url, $ext)
92 92
     {
93
-        $filepath = sys_get_temp_dir() . '/' . uniqid() . '.' . $ext;
93
+        $filepath = sys_get_temp_dir().'/'.uniqid().'.'.$ext;
94 94
         $ch = curl_init($url);
95 95
         $fp = fopen($filepath, 'wb');
96 96
         curl_setopt($ch, CURLOPT_FILE, $fp);
@@ -105,16 +105,16 @@  discard block
 block discarded – undo
105 105
     protected function fetchFromCache($key)
106 106
     {
107 107
         $fs = new Filesystem();
108
-        $cacheDir = $_SERVER['HOME'] . '/.symfony/media';
108
+        $cacheDir = $_SERVER['HOME'].'/.symfony/media';
109 109
         if (!$fs->exists($cacheDir)) {
110 110
             $fs->mkdir($cacheDir, 0777);
111 111
         } else {
112
-            $cacheDir .= '/' . $key;
112
+            $cacheDir .= '/'.$key;
113 113
             if (!$fs->exists($cacheDir)) {
114 114
                 $fs->mkdir($cacheDir, 0777);
115 115
             } else {
116 116
                 $finder = new Finder();
117
-                $files = $finder->in($cacheDir . '/')->files();
117
+                $files = $finder->in($cacheDir.'/')->files();
118 118
                 if (strrpos($key, "file-") !== false || $files->count() === 3) {
119 119
                     $iterator = $finder->getIterator();
120 120
                     $iterator->rewind();
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
                         $iterator->next();
123 123
                     }
124 124
                     $file = new File($iterator->current());
125
-                    $fs->copy($file->getRealPath(), sys_get_temp_dir() . '/' . $file->getFilename());
125
+                    $fs->copy($file->getRealPath(), sys_get_temp_dir().'/'.$file->getFilename());
126 126
 
127
-                    return new File(sys_get_temp_dir() . '/' . $file->getFilename());
127
+                    return new File(sys_get_temp_dir().'/'.$file->getFilename());
128 128
                 }
129 129
             }
130 130
         }
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
     protected function storeInCache($key, File $file)
134 134
     {
135 135
         $fs = new Filesystem();
136
-        $cacheDir = $_SERVER['HOME'] . '/.symfony/media/' . $key;
136
+        $cacheDir = $_SERVER['HOME'].'/.symfony/media/'.$key;
137 137
         if (!$fs->exists($cacheDir)) {
138 138
             $fs->mkdir($cacheDir, 0777);
139 139
         }
140
-        $fs->copy($file->getRealPath(), $cacheDir . '/' . $file->getFilename());
140
+        $fs->copy($file->getRealPath(), $cacheDir.'/'.$file->getFilename());
141 141
     }
142 142
 }
Please login to merge, or discard this patch.