Completed
Push — develop ( e426e7...538b88 )
by Paul
02:06
created
src/Video.php 1 patch
Spacing   +21 added lines, -21 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,37 +55,37 @@  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>',
64
+		if (!$this->args['image'])return;
65
+		return sprintf('<div class="video-screenshot" style="background-image: url(%s)">%s</div>',
66 66
 			$this->args['image'],
67 67
 			$this->renderPlayButton()
68 68
 		);
69 69
 	}
70 70
 
71
-	protected function setImage( $image )
71
+	protected function setImage($image)
72 72
 	{
73
-		$image = $this->image->get( $image )->image;
74
-		$this->args['image'] = isset( $image->large )
73
+		$image = $this->image->get($image)->image;
74
+		$this->args['image'] = isset($image->large)
75 75
 			? $image->large['url']
76 76
 			: null;
77 77
 	}
78 78
 
79
-	protected function setUrl( $url )
79
+	protected function setUrl($url)
80 80
 	{
81
-		$this->args['url'] = !filter_var( $url, FILTER_VALIDATE_URL )
82
-			? $this->postmeta->get( $url )
81
+		$this->args['url'] = !filter_var($url, FILTER_VALIDATE_URL)
82
+			? $this->postmeta->get($url)
83 83
 			: $url;
84 84
 	}
85 85
 
86
-	protected function normalize( $args )
86
+	protected function normalize($args)
87 87
 	{
88
-		if( is_string( $args )) {
88
+		if (is_string($args)) {
89 89
 			$args = ['url' => $args];
90 90
 		}
91 91
 
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
 			'image'  => '', // string || int
94 94
 			'player' => '', // string || array
95 95
 			'url'    => '', // string
96
-		], $args );
96
+		], $args);
97 97
 
98
-		foreach( $this->args as $key => $value ) {
99
-			$method = $this->utility->buildMethodName( $key, 'set' );
100
-			if( !method_exists( $this, $method ))continue;
101
-			call_user_func([ $this, $method ], $value );
98
+		foreach ($this->args as $key => $value) {
99
+			$method = $this->utility->buildMethodName($key, 'set');
100
+			if (!method_exists($this, $method))continue;
101
+			call_user_func([$this, $method], $value);
102 102
 		}
103 103
 		return $this->args;
104 104
 	}
Please login to merge, or discard this patch.
src/Image.php 1 patch
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( !$attachmentId || !$attachment || $attachment->post_type != 'attachment' )return;
62
+		if (!$attachmentId || !$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.
src/Helpers/Media.php 1 patch
Spacing   +20 added lines, -20 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,21 +34,21 @@  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 );
40
-		if( !$mediaType ) {
41
-			throw new BadMethodCallException( sprintf( 'Not a valid method: %s', $name ));
39
+		$mediaType = $this->validateMethod($name);
40
+		if (!$mediaType) {
41
+			throw new BadMethodCallException(sprintf('Not a valid method: %s', $name));
42 42
 		}
43
-		if( !count( $args )) {
44
-			throw new BadMethodCallException( sprintf( 'Missing arguments for: %s', $name ));
43
+		if (!count($args)) {
44
+			throw new BadMethodCallException(sprintf('Missing arguments for: %s', $name));
45 45
 		}
46
-		if( str_replace( $mediaType, '', strtolower( $name ))) {
47
-			return $this->$mediaType->get( $args[0] )->$mediaType;
46
+		if (str_replace($mediaType, '', strtolower($name))) {
47
+			return $this->$mediaType->get($args[0])->$mediaType;
48 48
 		}
49
-		return !empty( $args[1] )
50
-			? $this->$mediaType->get( $args[0] )->render( $args[1] )
51
-			: $this->$mediaType->get( $args[0] )->render();
49
+		return !empty($args[1])
50
+			? $this->$mediaType->get($args[0])->render($args[1])
51
+			: $this->$mediaType->get($args[0])->render();
52 52
 	}
53 53
 
54 54
 	/**
@@ -57,10 +57,10 @@  discard block
 block discarded – undo
57 57
 	 *
58 58
 	 * @return mixed
59 59
 	 */
60
-	public function get( $name, $args = [] )
60
+	public function get($name, $args = [])
61 61
 	{
62
-		if( $mediaType = $this->validateMethod( $name )) {
63
-			return $this->$mediaType->get( $args )->$mediaType;
62
+		if ($mediaType = $this->validateMethod($name)) {
63
+			return $this->$mediaType->get($args)->$mediaType;
64 64
 		}
65 65
 	}
66 66
 
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return string|false
71 71
 	 */
72
-	protected function validateMethod( $name )
72
+	protected function validateMethod($name)
73 73
 	{
74
-		foreach( [$name, strtolower( substr( $name, 3 ))] as $method ) {
75
-			if( in_array( $method, ['gallery', 'image', 'video'] )
76
-				&& property_exists( $this, $method )
77
-				&& is_object( $this->$method )) {
74
+		foreach ([$name, strtolower(substr($name, 3))] as $method) {
75
+			if (in_array($method, ['gallery', 'image', 'video'])
76
+				&& property_exists($this, $method)
77
+				&& is_object($this->$method)) {
78 78
 				return $method;
79 79
 			}
80 80
 		}
Please login to merge, or discard this patch.
src/Oembed.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -22,65 +22,65 @@
 block discarded – undo
22 22
 		'width',
23 23
 	];
24 24
 
25
-	public function __construct( Utility $utility )
25
+	public function __construct(Utility $utility)
26 26
 	{
27 27
 		$this->oembed  = _wp_oembed_get_object();
28 28
 		$this->utility = $utility;
29 29
 	}
30 30
 
31
-	public function request( $url, $args = '' )
31
+	public function request($url, $args = '')
32 32
 	{
33
-		$request = $this->oembed->fetch( $this->oembed->get_provider( $url ), $url, [
33
+		$request = $this->oembed->fetch($this->oembed->get_provider($url), $url, [
34 34
 			'width'  => 1280,
35 35
 			'height' => 1280,
36 36
 		]);
37
-		if( $request ) {
38
-			return $this->modifyRequest( $request, $args );
37
+		if ($request) {
38
+			return $this->modifyRequest($request, $args);
39 39
 		}
40 40
 	}
41 41
 
42
-	protected function domLoad( $html )
42
+	protected function domLoad($html)
43 43
 	{
44 44
 		$dom = new DomDocument;
45
-		$dom->loadHTML( $html );
45
+		$dom->loadHTML($html);
46 46
 		return $dom;
47 47
 	}
48 48
 
49
-	protected function modifyRequest( $request, $args )
49
+	protected function modifyRequest($request, $args)
50 50
 	{
51
-		$providerName = strtolower( $request->provider_name );
52
-		$provider = property_exists( $this, $providerName )
51
+		$providerName = strtolower($request->provider_name);
52
+		$provider = property_exists($this, $providerName)
53 53
 			? $this->$providerName
54 54
 			: [];
55 55
 
56
-		$method = $this->utility->buildMethodName( $providerName . '_request', 'modify' );
56
+		$method = $this->utility->buildMethodName($providerName . '_request', 'modify');
57 57
 
58
-		if( method_exists( $this, $method )) {
59
-			return call_user_func( [$this, $method], $request, array_intersect_key(
60
-				wp_parse_args( $args ),
61
-				array_flip( $provider )
58
+		if (method_exists($this, $method)) {
59
+			return call_user_func([$this, $method], $request, array_intersect_key(
60
+				wp_parse_args($args),
61
+				array_flip($provider)
62 62
 			));
63 63
 		}
64 64
 		return $request;
65 65
 	}
66 66
 
67
-	protected function modifyYoutubeRequest( $request, array $args )
67
+	protected function modifyYoutubeRequest($request, array $args)
68 68
 	{
69
-		$html = $this->domLoad( $request->html );
70
-		$node = $html->getElementsByTagName( 'iframe' )->item(0);
71
-		$url  = $node->getAttribute( 'src' );
69
+		$html = $this->domLoad($request->html);
70
+		$node = $html->getElementsByTagName('iframe')->item(0);
71
+		$url  = $node->getAttribute('src');
72 72
 
73
-		if( isset( $args['fs'] ) && $args['fs'] == 0 ) {
74
-			$node->removeAttribute( 'allowfullscreen' );
73
+		if (isset($args['fs']) && $args['fs'] == 0) {
74
+			$node->removeAttribute('allowfullscreen');
75 75
 		}
76 76
 
77
-		$args['origin'] = urlencode( get_bloginfo( 'url' ));
77
+		$args['origin'] = urlencode(get_bloginfo('url'));
78 78
 
79
-		$node->setAttribute( 'src',
80
-			add_query_arg( $args, remove_query_arg( 'feature', $url ))
79
+		$node->setAttribute('src',
80
+			add_query_arg($args, remove_query_arg('feature', $url))
81 81
 		);
82 82
 
83
-		$request->html = $html->saveHTML( $node );
83
+		$request->html = $html->saveHTML($node);
84 84
 
85 85
 		return $request;
86 86
 	}
Please login to merge, or discard this patch.