Completed
Push — develop ( be9e19...7c5a9c )
by Paul
02:01
created
src/Image.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 	protected $postmeta;
13 13
 	protected $utility;
14 14
 
15
-	public function __construct( PostMeta $postmeta, Utility $utility )
15
+	public function __construct(PostMeta $postmeta, Utility $utility)
16 16
 	{
17 17
 		$this->postmeta = $postmeta;
18 18
 		$this->utility  = $utility;
@@ -23,43 +23,43 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @return self
25 25
 	 */
26
-	public function get( $attachment )
26
+	public function get($attachment)
27 27
 	{
28
-		if( !( $attachment = $this->normalize( $attachment )))return;
29
-		if( $thumbnail = wp_get_attachment_image_src( $attachment, 'thumbnail' )) {
30
-			$medium = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'medium' ), $thumbnail );
31
-			$large = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'large' ), $medium );
28
+		if (!($attachment = $this->normalize($attachment)))return;
29
+		if ($thumbnail = wp_get_attachment_image_src($attachment, 'thumbnail')) {
30
+			$medium = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'medium'), $thumbnail);
31
+			$large = $this->normalizeSrc(wp_get_attachment_image_src($attachment, 'large'), $medium);
32 32
 
33 33
 			$this->image = (object) [
34
-				'alt'       => wp_strip_all_tags( get_post_meta( $attachment, '_wp_attachment_image_alt', true ), true ),
35
-				'caption'   => wp_get_attachment_caption( $attachment ),
36
-				'copyright' => wp_strip_all_tags( get_post_meta( $attachment, '_copyright', true ), true ),
34
+				'alt'       => wp_strip_all_tags(get_post_meta($attachment, '_wp_attachment_image_alt', true), true),
35
+				'caption'   => wp_get_attachment_caption($attachment),
36
+				'copyright' => wp_strip_all_tags(get_post_meta($attachment, '_copyright', true), true),
37 37
 				'ID'        => $attachment,
38 38
 				'large'     => $large,
39 39
 				'medium'    => $medium,
40
-				'permalink' => get_attachment_link( $attachment ),
41
-				'thumbnail' => $this->normalizeSrc( $thumbnail ),
40
+				'permalink' => get_attachment_link($attachment),
41
+				'thumbnail' => $this->normalizeSrc($thumbnail),
42 42
 			];
43 43
 		}
44 44
 		return $this;
45 45
 	}
46 46
 
47
-	public function render( $size = 'large' )
47
+	public function render($size = 'large')
48 48
 	{
49
-		if( $this->image ) {
50
-			return wp_get_attachment_image( $this->image->ID, $size );
49
+		if ($this->image) {
50
+			return wp_get_attachment_image($this->image->ID, $size);
51 51
 		}
52 52
 	}
53 53
 
54
-	protected function normalize( $attachmentId )
54
+	protected function normalize($attachmentId)
55 55
 	{
56
-		if( !filter_var( $attachmentId, FILTER_VALIDATE_INT )) {
57
-			$attachmentId = $this->postmeta->get( $attachmentId );
56
+		if (!filter_var($attachmentId, FILTER_VALIDATE_INT)) {
57
+			$attachmentId = $this->postmeta->get($attachmentId);
58 58
 		}
59 59
 
60
-		$attachment = get_post( $attachmentId );
60
+		$attachment = get_post($attachmentId);
61 61
 
62
-		if( is_null( $attachment ) || $attachment->post_type != 'attachment' )return;
62
+		if (is_null($attachment) || $attachment->post_type != 'attachment')return;
63 63
 
64 64
 		return $attachment->ID;
65 65
 	}
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return array
71 71
 	 */
72
-	protected function normalizeSrc( array $image, $fallback = false )
72
+	protected function normalizeSrc(array $image, $fallback = false)
73 73
 	{
74
-		if( is_array( $fallback ) && count( array_diff( $image, $fallback )) < 2 ) {
74
+		if (is_array($fallback) && count(array_diff($image, $fallback)) < 2) {
75 75
 			$image = $fallback;
76 76
 		}
77 77
 		return [
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@  discard block
 block discarded – undo
25 25
 	 */
26 26
 	public function get( $attachment )
27 27
 	{
28
-		if( !( $attachment = $this->normalize( $attachment )))return;
28
+		if( !( $attachment = $this->normalize( $attachment ))) {
29
+			return;
30
+		}
29 31
 		if( $thumbnail = wp_get_attachment_image_src( $attachment, 'thumbnail' )) {
30 32
 			$medium = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'medium' ), $thumbnail );
31 33
 			$large = $this->normalizeSrc( wp_get_attachment_image_src( $attachment, 'large' ), $medium );
@@ -59,7 +61,9 @@  discard block
 block discarded – undo
59 61
 
60 62
 		$attachment = get_post( $attachmentId );
61 63
 
62
-		if( is_null( $attachment ) || $attachment->post_type != 'attachment' )return;
64
+		if( is_null( $attachment ) || $attachment->post_type != 'attachment' ) {
65
+			return;
66
+		}
63 67
 
64 68
 		return $attachment->ID;
65 69
 	}
Please login to merge, or discard this patch.