@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * @param $image |
33 | 33 | * @param $imageable |
34 | 34 | * @param null $data |
35 | - * @param null $location |
|
36 | - * @return static |
|
35 | + * @param string $location |
|
36 | + * @return Image|null |
|
37 | 37 | * @throws Exception |
38 | 38 | */ |
39 | 39 | public function uploadAndCreate($image, $imageable, $data = null, $location = null) |
@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * Download image to server and get as UploadedFile object. |
57 | 57 | * |
58 | - * @param $url |
|
58 | + * @param string $url |
|
59 | 59 | * @param $imageable |
60 | 60 | * @param array|null $data |
61 | 61 | * @param string $location |
62 | - * @return static |
|
62 | + * @return Image |
|
63 | 63 | */ |
64 | 64 | public function downloadAndUpload($url, $imageable, array $data = null, $location = 'upload/images/') |
65 | 65 | { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | /** |
145 | 145 | * Set location. |
146 | 146 | * |
147 | - * @param $location |
|
147 | + * @param string $location |
|
148 | 148 | * @return $this |
149 | 149 | */ |
150 | 150 | public function setLocation($location) |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
158 | - * @param $location |
|
158 | + * @param string $location |
|
159 | 159 | * @throws Exception |
160 | 160 | */ |
161 | 161 | protected function validateLocation($location) |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | /** |
213 | 213 | * Standart pattern. |
214 | 214 | * |
215 | - * @param $location |
|
216 | - * @param $filename |
|
217 | - * @param $extension |
|
215 | + * @param string $location |
|
216 | + * @param string $filename |
|
217 | + * @param string|null $extension |
|
218 | 218 | * @return string |
219 | 219 | */ |
220 | 220 | private function pattern($filename, $extension, $location = null) |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use App\Image; |
6 | 6 | use Exception; |
7 | -use Illuminate\Database\Eloquent\Model; |
|
8 | 7 | use Illuminate\Http\UploadedFile; |
9 | 8 | |
10 | 9 | class ImageProcessor |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function uploadAndCreate($image, $imageable, $data = null, $location = null) |
40 | 40 | { |
41 | - if($this->validateImage($image)) { |
|
41 | + if ($this->validateImage($image)) { |
|
42 | 42 | $original = $image->getClientOriginalName(); |
43 | 43 | if (isset($location)) |
44 | 44 | $this->setLocation($location); |
45 | 45 | |
46 | - $data['original'] = $original; |
|
46 | + $data[ 'original' ] = $original; |
|
47 | 47 | |
48 | 48 | if ($imageInfo = $this->upload($image)) |
49 | 49 | { |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | public function downloadAndUpload($url, $imageable, array $data = null, $location = 'upload/images/') |
65 | 65 | { |
66 | 66 | $file = file_get_contents($url); // download the image from url. |
67 | - $extension = $this->parseExtension(getimagesize($url)['mime']); |
|
67 | + $extension = $this->parseExtension(getimagesize($url)[ 'mime' ]); |
|
68 | 68 | |
69 | 69 | if (isset($location)) |
70 | 70 | $this->setLocation($location); |
71 | - $filename = time() .'_'. str_random(15); |
|
71 | + $filename = time().'_'.str_random(15); |
|
72 | 72 | |
73 | 73 | $path_to_image = $this->pattern($filename, $extension, $location); |
74 | 74 | file_put_contents($path_to_image, $file); |
75 | 75 | |
76 | 76 | $imageInfo = new UploadedFile($path_to_image, str_random(10)); |
77 | - $data = array_merge(['original' => $filename], $data); |
|
77 | + $data = array_merge([ 'original' => $filename ], $data); |
|
78 | 78 | |
79 | 79 | return $this->create($imageInfo->getRealPath(), $imageable, $data); |
80 | 80 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function destroy($image) |
119 | 119 | { |
120 | - if($image) { |
|
120 | + if ($image) { |
|
121 | 121 | $location = ltrim($image->image, '/'); |
122 | 122 | @unlink(base_path("public/{$location}")); |
123 | 123 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function destroyImageOnly($image) |
135 | 135 | { |
136 | - if($image) { |
|
136 | + if ($image) { |
|
137 | 137 | $location = ltrim($image->image, '/'); |
138 | 138 | return @unlink(base_path("public/{$location}")); |
139 | 139 | } |
@@ -162,20 +162,20 @@ discard block |
||
162 | 162 | { |
163 | 163 | $fileExists = file_exists($location); |
164 | 164 | |
165 | - if ((! $fileExists && ! mkdir($location, 0777, true)) || ! is_writeable($location)) { |
|
165 | + if ((!$fileExists && !mkdir($location, 0777, true)) || !is_writeable($location)) { |
|
166 | 166 | throw new Exception("Location [$location] not exists or not writable"); |
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
170 | 170 | protected function upload($image) |
171 | 171 | { |
172 | - $location = base_path("public/" . $this->location); |
|
172 | + $location = base_path("public/".$this->location); |
|
173 | 173 | |
174 | 174 | $this->validateLocation($location); |
175 | 175 | |
176 | 176 | if ($image) { |
177 | 177 | if ($image->isValid()) { |
178 | - $filename = rtrim($location, '/') . '/' . ltrim($this->getNewImageName($image), '/'); |
|
178 | + $filename = rtrim($location, '/').'/'.ltrim($this->getNewImageName($image), '/'); |
|
179 | 179 | |
180 | 180 | $this->filename = $filename; |
181 | 181 | |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | if ($old_avatar = \Auth::user()->images()->avatar()->first()) |
199 | 199 | $this->destroy($old_avatar); |
200 | 200 | |
201 | - if(is_string($avatar)) { // check if url. |
|
202 | - $this->downloadAndUpload($avatar, \Auth::user(), ['type' => 'avatar'], $location); |
|
201 | + if (is_string($avatar)) { // check if url. |
|
202 | + $this->downloadAndUpload($avatar, \Auth::user(), [ 'type' => 'avatar' ], $location); |
|
203 | 203 | |
204 | 204 | return $this; |
205 | 205 | } |
206 | 206 | |
207 | - $this->uploadAndCreate($avatar, \Auth::user(), ['type' => 'avatar'], $location); |
|
207 | + $this->uploadAndCreate($avatar, \Auth::user(), [ 'type' => 'avatar' ], $location); |
|
208 | 208 | |
209 | 209 | return $this; |
210 | 210 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | private function pattern($filename, $extension, $location = null) |
221 | 221 | { |
222 | - if(! $location) |
|
222 | + if (!$location) |
|
223 | 223 | return sprintf('%s.%s', $filename, $extension); |
224 | 224 | |
225 | 225 | return sprintf('%s%s.%s', $location, $filename, $extension); |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | return $this->getModel()->create([ |
259 | 259 | 'imageable_id' => $imageable->id, |
260 | 260 | 'imageable_type' => get_class($imageable), |
261 | - 'type' => isset($data['type']) ? $data['type'] : 'cover', |
|
262 | - 'original' => isset($data['original']) ? $data['original'] : str_random(13), |
|
261 | + 'type' => isset($data[ 'type' ]) ? $data[ 'type' ] : 'cover', |
|
262 | + 'original' => isset($data[ 'original' ]) ? $data[ 'original' ] : str_random(13), |
|
263 | 263 | 'image' => str_replace(base_path('public'), '', $path), |
264 | 264 | ]); |
265 | 265 | } |
@@ -40,8 +40,9 @@ discard block |
||
40 | 40 | { |
41 | 41 | if($this->validateImage($image)) { |
42 | 42 | $original = $image->getClientOriginalName(); |
43 | - if (isset($location)) |
|
44 | - $this->setLocation($location); |
|
43 | + if (isset($location)) { |
|
44 | + $this->setLocation($location); |
|
45 | + } |
|
45 | 46 | |
46 | 47 | $data['original'] = $original; |
47 | 48 | |
@@ -66,8 +67,9 @@ discard block |
||
66 | 67 | $file = file_get_contents($url); // download the image from url. |
67 | 68 | $extension = $this->parseExtension(getimagesize($url)['mime']); |
68 | 69 | |
69 | - if (isset($location)) |
|
70 | - $this->setLocation($location); |
|
70 | + if (isset($location)) { |
|
71 | + $this->setLocation($location); |
|
72 | + } |
|
71 | 73 | $filename = time() .'_'. str_random(15); |
72 | 74 | |
73 | 75 | $path_to_image = $this->pattern($filename, $extension, $location); |
@@ -195,8 +197,9 @@ discard block |
||
195 | 197 | */ |
196 | 198 | public function changeAvatar($avatar, $location = 'upload/images/user_avatars/') |
197 | 199 | { |
198 | - if ($old_avatar = \Auth::user()->images()->avatar()->first()) |
|
199 | - $this->destroy($old_avatar); |
|
200 | + if ($old_avatar = \Auth::user()->images()->avatar()->first()) { |
|
201 | + $this->destroy($old_avatar); |
|
202 | + } |
|
200 | 203 | |
201 | 204 | if(is_string($avatar)) { // check if url. |
202 | 205 | $this->downloadAndUpload($avatar, \Auth::user(), ['type' => 'avatar'], $location); |
@@ -219,8 +222,9 @@ discard block |
||
219 | 222 | */ |
220 | 223 | private function pattern($filename, $extension, $location = null) |
221 | 224 | { |
222 | - if(! $location) |
|
223 | - return sprintf('%s.%s', $filename, $extension); |
|
225 | + if(! $location) { |
|
226 | + return sprintf('%s.%s', $filename, $extension); |
|
227 | + } |
|
224 | 228 | |
225 | 229 | return sprintf('%s%s.%s', $location, $filename, $extension); |
226 | 230 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | - * @return mixed |
|
73 | + * @return string |
|
74 | 74 | */ |
75 | 75 | public function getProvider() |
76 | 76 | { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | /** |
230 | 230 | * Login the user. |
231 | 231 | * |
232 | - * @param $user |
|
232 | + * @param \App\User $user |
|
233 | 233 | */ |
234 | 234 | public function login($user) |
235 | 235 | { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $this->getProvider(), $this->user()->getId() |
56 | 56 | ); |
57 | 57 | |
58 | - if($user = $s_user->user) |
|
58 | + if ($user = $s_user->user) |
|
59 | 59 | return $user; |
60 | 60 | |
61 | 61 | return $this; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | $social = $this->getOrCreateEmptySocialUser(); |
65 | 65 | |
66 | - if($this->checkEmail()) |
|
66 | + if ($this->checkEmail()) |
|
67 | 67 | return $this->createSocialUserWithEmail($social); |
68 | 68 | |
69 | 69 | return $this; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function getOrCreateEmptySocialUser() |
128 | 128 | { |
129 | - if($this->socialRepository->checkProviderUser($this->getProvider(), $this->user()->getId())) |
|
129 | + if ($this->socialRepository->checkProviderUser($this->getProvider(), $this->user()->getId())) |
|
130 | 130 | return $this->socialRepository->getUserByProvider($this->getProvider(), $this->user()->getId()); |
131 | 131 | |
132 | 132 | return $this->socialRepository->createEmpty( |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | private function associateSocialiteUser($account, $email = null) |
161 | 161 | { |
162 | - if(! $email) |
|
162 | + if (!$email) |
|
163 | 163 | $email = $this->user()->getEmail(); |
164 | 164 | |
165 | 165 | $user = $this->getUserRepository()->getByEmail($email); |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function tryToAssociateUser($social, $email = null) |
187 | 187 | { |
188 | - if(! $email) |
|
188 | + if (!$email) |
|
189 | 189 | $email = $this->user()->getEmail(); |
190 | 190 | |
191 | - if($this->getUserRepository()->checkIfUserExists($email)) |
|
191 | + if ($this->getUserRepository()->checkIfUserExists($email)) |
|
192 | 192 | return $this->associateSocialiteUser($social, $email); |
193 | 193 | |
194 | 194 | return false; |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | 'email' => $this->user()->getEmail(), |
210 | 210 | 'name' => $this->user()->getName(), |
211 | 211 | 'password' => $this->users->hashPassword(str_random(45)), |
212 | - 'firstname' => @$names[0], |
|
213 | - 'lastname' => @$names[1] |
|
212 | + 'firstname' => @$names[ 0 ], |
|
213 | + 'lastname' => @$names[ 1 ] |
|
214 | 214 | ]); |
215 | 215 | } |
216 | 216 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | */ |
221 | 221 | public function getFirstAndLustNames($name = null) |
222 | 222 | { |
223 | - if(! $name) |
|
223 | + if (!$name) |
|
224 | 224 | $name = $this->user()->getName(); |
225 | 225 | |
226 | 226 | return explode(' ', $name); |
@@ -55,16 +55,18 @@ discard block |
||
55 | 55 | $this->getProvider(), $this->user()->getId() |
56 | 56 | ); |
57 | 57 | |
58 | - if($user = $s_user->user) |
|
59 | - return $user; |
|
58 | + if($user = $s_user->user) { |
|
59 | + return $user; |
|
60 | + } |
|
60 | 61 | |
61 | 62 | return $this; |
62 | 63 | } |
63 | 64 | |
64 | 65 | $social = $this->getOrCreateEmptySocialUser(); |
65 | 66 | |
66 | - if($this->checkEmail()) |
|
67 | - return $this->createSocialUserWithEmail($social); |
|
67 | + if($this->checkEmail()) { |
|
68 | + return $this->createSocialUserWithEmail($social); |
|
69 | + } |
|
68 | 70 | |
69 | 71 | return $this; |
70 | 72 | } |
@@ -126,8 +128,9 @@ discard block |
||
126 | 128 | */ |
127 | 129 | protected function getOrCreateEmptySocialUser() |
128 | 130 | { |
129 | - if($this->socialRepository->checkProviderUser($this->getProvider(), $this->user()->getId())) |
|
130 | - return $this->socialRepository->getUserByProvider($this->getProvider(), $this->user()->getId()); |
|
131 | + if($this->socialRepository->checkProviderUser($this->getProvider(), $this->user()->getId())) { |
|
132 | + return $this->socialRepository->getUserByProvider($this->getProvider(), $this->user()->getId()); |
|
133 | + } |
|
131 | 134 | |
132 | 135 | return $this->socialRepository->createEmpty( |
133 | 136 | $this->getProvider(), $this->user() |
@@ -159,8 +162,9 @@ discard block |
||
159 | 162 | */ |
160 | 163 | private function associateSocialiteUser($account, $email = null) |
161 | 164 | { |
162 | - if(! $email) |
|
163 | - $email = $this->user()->getEmail(); |
|
165 | + if(! $email) { |
|
166 | + $email = $this->user()->getEmail(); |
|
167 | + } |
|
164 | 168 | |
165 | 169 | $user = $this->getUserRepository()->getByEmail($email); |
166 | 170 | $account->user()->associate($user); |
@@ -185,11 +189,13 @@ discard block |
||
185 | 189 | */ |
186 | 190 | public function tryToAssociateUser($social, $email = null) |
187 | 191 | { |
188 | - if(! $email) |
|
189 | - $email = $this->user()->getEmail(); |
|
192 | + if(! $email) { |
|
193 | + $email = $this->user()->getEmail(); |
|
194 | + } |
|
190 | 195 | |
191 | - if($this->getUserRepository()->checkIfUserExists($email)) |
|
192 | - return $this->associateSocialiteUser($social, $email); |
|
196 | + if($this->getUserRepository()->checkIfUserExists($email)) { |
|
197 | + return $this->associateSocialiteUser($social, $email); |
|
198 | + } |
|
193 | 199 | |
194 | 200 | return false; |
195 | 201 | } |
@@ -220,8 +226,9 @@ discard block |
||
220 | 226 | */ |
221 | 227 | public function getFirstAndLustNames($name = null) |
222 | 228 | { |
223 | - if(! $name) |
|
224 | - $name = $this->user()->getName(); |
|
229 | + if(! $name) { |
|
230 | + $name = $this->user()->getName(); |
|
231 | + } |
|
225 | 232 | |
226 | 233 | return explode(' ', $name); |
227 | 234 | } |
@@ -111,7 +111,7 @@ |
||
111 | 111 | /** |
112 | 112 | * Check if user has wallet. |
113 | 113 | * |
114 | - * @return bool |
|
114 | + * @return boolean|null |
|
115 | 115 | */ |
116 | 116 | public function haveWallet() |
117 | 117 | { |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function isSocialite() |
90 | 90 | { |
91 | - return (bool)$this->socialite; |
|
91 | + return (bool) $this->socialite; |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public function checkAvatar() |
100 | 100 | { |
101 | - return (bool)$this->images()->avatar()->first(); |
|
101 | + return (bool) $this->images()->avatar()->first(); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | public function isAdmin() |
@@ -19,12 +19,12 @@ |
||
19 | 19 | */ |
20 | 20 | public function rules() |
21 | 21 | { |
22 | - \Validator::extend('old_password', function ($attribute, $value, $parameters, $validator) { |
|
22 | + \Validator::extend('old_password', function($attribute, $value, $parameters, $validator) { |
|
23 | 23 | return \Hash::check($value, current($parameters)); |
24 | 24 | }); |
25 | 25 | |
26 | 26 | return [ |
27 | - 'old_password' => 'required|old_password:' . Auth::user()->password, |
|
27 | + 'old_password' => 'required|old_password:'.Auth::user()->password, |
|
28 | 28 | 'password' => 'required|min:6|confirmed', |
29 | 29 | ]; |
30 | 30 | } |
@@ -40,7 +40,7 @@ |
||
40 | 40 | public function rules() |
41 | 41 | { |
42 | 42 | return [ |
43 | - 'name' => 'required|min:3|max:250|unique:vendors,name,' . $this->route('vendor')->id, |
|
43 | + 'name' => 'required|min:3|max:250|unique:vendors,name,'.$this->route('vendor')->id, |
|
44 | 44 | 'email' => 'email', |
45 | 45 | 'phone' => 'required|digits:8', |
46 | 46 | 'description' => 'min:10|max:250' |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public function authorize() |
13 | 13 | { |
14 | - if(! Auth::user()->confirmed) |
|
14 | + if (!Auth::user()->confirmed) |
|
15 | 15 | return true; |
16 | 16 | |
17 | 17 | return false; |
@@ -22,6 +22,6 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public function rules() |
24 | 24 | { |
25 | - return []; |
|
25 | + return [ ]; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -11,8 +11,9 @@ |
||
11 | 11 | */ |
12 | 12 | public function authorize() |
13 | 13 | { |
14 | - if(! Auth::user()->confirmed) |
|
15 | - return true; |
|
14 | + if(! Auth::user()->confirmed) { |
|
15 | + return true; |
|
16 | + } |
|
16 | 17 | |
17 | 18 | return false; |
18 | 19 | } |
@@ -9,7 +9,7 @@ |
||
9 | 9 | */ |
10 | 10 | public function authorize() |
11 | 11 | { |
12 | - return (bool)!$this->route()->getParameter('social')->user; |
|
12 | + return (bool) !$this->route()->getParameter('social')->user; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -22,7 +22,7 @@ |
||
22 | 22 | 'fname' => 'required|min:3|max:20', |
23 | 23 | 'lname' => 'required|min:3|max:20', |
24 | 24 | 'phone' => 'required|digits:8', |
25 | - 'email' => 'required|unique:users,email,' . \Auth::id() . ',id', |
|
25 | + 'email' => 'required|unique:users,email,'.\Auth::id().',id', |
|
26 | 26 | ]; |
27 | 27 | } |
28 | 28 | } |
29 | 29 | \ No newline at end of file |
@@ -15,9 +15,10 @@ |
||
15 | 15 | |
16 | 16 | if ($involve |
17 | 17 | && $this->getInvolvedRepository()->checkIfAuthInvolved($involve->product) |
18 | - ) |
|
19 | - if ($involve->active !== 0) { |
|
18 | + ) { |
|
19 | + if ($involve->active !== 0) { |
|
20 | 20 | return true; |
21 | + } |
|
21 | 22 | } |
22 | 23 | |
23 | 24 | return false; |