Completed
Push — develop ( 251fde...5649b4 )
by Paul
02:11
created
src/Helpers/Media.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	protected $image;
22 22
 	protected $video;
23 23
 
24
-	public function __construct( Gallery $gallery, Image $image, Video $video )
24
+	public function __construct(Gallery $gallery, Image $image, Video $video)
25 25
 	{
26 26
 		$this->gallery = $gallery;
27 27
 		$this->image   = $image;
@@ -34,19 +34,19 @@  discard block
 block discarded – undo
34 34
 	 * @return string|void
35 35
 	 * @throws BadMethodCallException
36 36
 	 */
37
-	public function __call( $name, array $args )
37
+	public function __call($name, array $args)
38 38
 	{
39
-		$mediaType = $this->validateMethod( $name );
39
+		$mediaType = $this->validateMethod($name);
40 40
 
41
-		if( !count( $args )) {
42
-			throw new BadMethodCallException( sprintf( 'Missing arguments for: %s', $name ));
41
+		if (!count($args)) {
42
+			throw new BadMethodCallException(sprintf('Missing arguments for: %s', $name));
43 43
 		}
44
-		if( str_replace( $mediaType, '', strtolower( $name ))) {
45
-			return $this->$mediaType->get( $args[0] )->$mediaType;
44
+		if (str_replace($mediaType, '', strtolower($name))) {
45
+			return $this->$mediaType->get($args[0])->$mediaType;
46 46
 		}
47
-		return !empty( $args[1] )
48
-			? $this->$mediaType->get( $args[0] )->render( $args[1] )
49
-			: $this->$mediaType->get( $args[0] )->render();
47
+		return !empty($args[1])
48
+			? $this->$mediaType->get($args[0])->render($args[1])
49
+			: $this->$mediaType->get($args[0])->render();
50 50
 	}
51 51
 
52 52
 	/**
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
 	 * @return mixed
57 57
 	 * @throws BadMethodCallException
58 58
 	 */
59
-	public function get( $name, $args = [] )
59
+	public function get($name, $args = [])
60 60
 	{
61
-		$mediaType = $this->validateMethod( $name );
62
-		return $this->$mediaType->get( $args )->$mediaType;
61
+		$mediaType = $this->validateMethod($name);
62
+		return $this->$mediaType->get($args)->$mediaType;
63 63
 	}
64 64
 
65 65
 	/**
@@ -68,13 +68,13 @@  discard block
 block discarded – undo
68 68
 	 * @return string|false
69 69
 	 * @throws BadMethodCallException
70 70
 	 */
71
-	protected function validateMethod( $name )
71
+	protected function validateMethod($name)
72 72
 	{
73
-		foreach( [$name, strtolower( substr( $name, 3 ))] as $method ) {
74
-			if( property_exists( $this, $method ) && is_object( $this->$method )) {
73
+		foreach ([$name, strtolower(substr($name, 3))] as $method) {
74
+			if (property_exists($this, $method) && is_object($this->$method)) {
75 75
 				return $method;
76 76
 			}
77 77
 		}
78
-		throw new BadMethodCallException( sprintf( 'Not a valid method: %s', $name ));
78
+		throw new BadMethodCallException(sprintf('Not a valid method: %s', $name));
79 79
 	}
80 80
 }
Please login to merge, or discard this patch.
src/Helpers/PostMeta.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,9 @@
 block discarded – undo
6 6
 {
7 7
 	public function get( $metaKey, array $args = [] )
8 8
 	{
9
-		if( empty( $metaKey ))return;
9
+		if( empty( $metaKey )) {
10
+			return;
11
+		}
10 12
 
11 13
 		$args = $this->normalize( $args );
12 14
 		$metaKey = $this->buildMetaKey( $metaKey, $args['prefix'] );
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -4,34 +4,34 @@
 block discarded – undo
4 4
 
5 5
 class PostMeta
6 6
 {
7
-	public function get( $metaKey, array $args = [] )
7
+	public function get($metaKey, array $args = [])
8 8
 	{
9
-		if( empty( $metaKey ))return;
9
+		if (empty($metaKey))return;
10 10
 
11
-		$args = $this->normalize( $args );
12
-		$metaKey = $this->buildMetaKey( $metaKey, $args['prefix'] );
13
-		$metaValue = get_post_meta( $args['ID'], $metaKey, $args['single'] );
11
+		$args = $this->normalize($args);
12
+		$metaKey = $this->buildMetaKey($metaKey, $args['prefix']);
13
+		$metaValue = get_post_meta($args['ID'], $metaKey, $args['single']);
14 14
 
15
-		return empty( $metaValue )
15
+		return empty($metaValue)
16 16
 			? $args['fallback']
17 17
 			: $metaValue;
18 18
 	}
19 19
 
20
-	protected function buildMetaKey( $metaKey, $prefix )
20
+	protected function buildMetaKey($metaKey, $prefix)
21 21
 	{
22
-		return ( substr( $metaKey, 0, 1 ) == '_' && !empty( $prefix ))
23
-			? sprintf( '_%s%s', rtrim( $prefix, '_' ), $metaKey )
22
+		return (substr($metaKey, 0, 1) == '_' && !empty($prefix))
23
+			? sprintf('_%s%s', rtrim($prefix, '_'), $metaKey)
24 24
 			: $prefix . $metaKey;
25 25
 	}
26 26
 
27
-	protected function normalize( array $args )
27
+	protected function normalize(array $args)
28 28
 	{
29 29
 		$defaults = [
30 30
 			'ID'       => get_the_ID(),
31 31
 			'fallback' => '',
32 32
 			'single'   => true,
33
-			'prefix'   => apply_filters( 'castor/postmeta/prefix', 'pollux_' ),
33
+			'prefix'   => apply_filters('castor/postmeta/prefix', 'pollux_'),
34 34
 		];
35
-		return shortcode_atts( $defaults, $args );
35
+		return shortcode_atts($defaults, $args);
36 36
 	}
37 37
 }
Please login to merge, or discard this patch.
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
-		$attachment = $this->normalize( $attachment );
29
-		if( $attachment && $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
+		$attachment = $this->normalize($attachment);
29
+		if ($attachment && $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   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@
 block discarded – undo
59 59
 
60 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' ) {
63
+			return;
64
+		}
63 65
 
64 66
 		return $attachment->ID;
65 67
 	}
Please login to merge, or discard this patch.
src/Video.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	protected $theme;
20 20
 	protected $utility;
21 21
 
22
-	public function __construct( Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility )
22
+	public function __construct(Image $image, Oembed $oembed, PostMeta $postmeta, Theme $theme, Utility $utility)
23 23
 	{
24 24
 		$this->image    = $image;
25 25
 		$this->oembed   = $oembed;
@@ -28,16 +28,16 @@  discard block
 block discarded – undo
28 28
 		$this->utility  = $utility;
29 29
 	}
30 30
 
31
-	public function get( $args = [] )
31
+	public function get($args = [])
32 32
 	{
33
-		$args = $this->normalize( $args );
34
-		$this->video = $this->oembed->request( $args['url'], $args['player'] );
33
+		$args = $this->normalize($args);
34
+		$this->video = $this->oembed->request($args['url'], $args['player']);
35 35
 		return $this;
36 36
 	}
37 37
 
38 38
 	public function render()
39 39
 	{
40
-		if( !isset( $this->video->html ))return;
40
+		if (!isset($this->video->html))return;
41 41
 		return sprintf(
42 42
 			'<div class="video embed">%s%s</div>',
43 43
 			$this->renderScreenshot(),
@@ -55,14 +55,14 @@  discard block
 block discarded – undo
55 55
 				'<a href="%s" class="video-play-btn">%s</a>' .
56 56
 			'</div>',
57 57
 			$this->args['url'],
58
-			$this->theme->svg( 'play.svg' )
58
+			$this->theme->svg('play.svg')
59 59
 		);
60 60
 	}
61 61
 
62 62
 	public function renderScreenshot()
63 63
 	{
64
-		if( !$this->args['image'] )return;
65
-		return sprintf( '<div class="video-screenshot" style="background-image: url(%s)">%s</div>%s',
64
+		if (!$this->args['image'])return;
65
+		return sprintf('<div class="video-screenshot" style="background-image: url(%s)">%s</div>%s',
66 66
 			$this->args['image'],
67 67
 			$this->renderPlayButton(),
68 68
 			$this->renderSpinner()
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
 			'<div class="video-spinner">' .
76 76
 				'<div class="spinner"><div class="spinner-dots">%s</div></div>' .
77 77
 			'</div>',
78
-			implode( '', array_fill( 0, 8, '<div class="spinner-dot"></div>' ))
78
+			implode('', array_fill(0, 8, '<div class="spinner-dot"></div>'))
79 79
 		);
80 80
 	}
81 81
 
82
-	protected function setImage( $image )
82
+	protected function setImage($image)
83 83
 	{
84
-		$image = $this->image->get( $image )->image;
85
-		$this->args['image'] = isset( $image->large )
84
+		$image = $this->image->get($image)->image;
85
+		$this->args['image'] = isset($image->large)
86 86
 			? $image->large['url']
87 87
 			: null;
88 88
 	}
89 89
 
90
-	protected function setUrl( $url )
90
+	protected function setUrl($url)
91 91
 	{
92
-		$this->args['url'] = !filter_var( $url, FILTER_VALIDATE_URL )
93
-			? $this->postmeta->get( $url )
92
+		$this->args['url'] = !filter_var($url, FILTER_VALIDATE_URL)
93
+			? $this->postmeta->get($url)
94 94
 			: $url;
95 95
 	}
96 96
 
97
-	protected function normalize( $args )
97
+	protected function normalize($args)
98 98
 	{
99
-		if( is_string( $args )) {
99
+		if (is_string($args)) {
100 100
 			$args = ['url' => $args];
101 101
 		}
102 102
 
@@ -104,12 +104,12 @@  discard block
 block discarded – undo
104 104
 			'image'  => '', // string || int
105 105
 			'player' => '', // string || array
106 106
 			'url'    => '', // string
107
-		], $args );
107
+		], $args);
108 108
 
109
-		foreach( $this->args as $key => $value ) {
110
-			$method = $this->utility->buildMethodName( $key, 'set' );
111
-			if( !method_exists( $this, $method ))continue;
112
-			call_user_func([ $this, $method ], $value );
109
+		foreach ($this->args as $key => $value) {
110
+			$method = $this->utility->buildMethodName($key, 'set');
111
+			if (!method_exists($this, $method))continue;
112
+			call_user_func([$this, $method], $value);
113 113
 		}
114 114
 		return $this->args;
115 115
 	}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,7 +37,9 @@  discard block
 block discarded – undo
37 37
 
38 38
 	public function render()
39 39
 	{
40
-		if( !isset( $this->video->html ))return;
40
+		if( !isset( $this->video->html )) {
41
+			return;
42
+		}
41 43
 		return sprintf(
42 44
 			'<div class="video embed">%s%s</div>',
43 45
 			$this->renderScreenshot(),
@@ -61,7 +63,9 @@  discard block
 block discarded – undo
61 63
 
62 64
 	public function renderScreenshot()
63 65
 	{
64
-		if( !$this->args['image'] )return;
66
+		if( !$this->args['image'] ) {
67
+			return;
68
+		}
65 69
 		return sprintf( '<div class="video-screenshot" style="background-image: url(%s)">%s</div>%s',
66 70
 			$this->args['image'],
67 71
 			$this->renderPlayButton(),
@@ -108,7 +112,9 @@  discard block
 block discarded – undo
108 112
 
109 113
 		foreach( $this->args as $key => $value ) {
110 114
 			$method = $this->utility->buildMethodName( $key, 'set' );
111
-			if( !method_exists( $this, $method ))continue;
115
+			if( !method_exists( $this, $method )) {
116
+				continue;
117
+			}
112 118
 			call_user_func([ $this, $method ], $value );
113 119
 		}
114 120
 		return $this->args;
Please login to merge, or discard this patch.