Completed
Push — master ( 24ed09...407117 )
by George
11:57 queued 02:11
created

Jetpack_Tiled_Gallery_Item::meta_height()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
abstract class Jetpack_Tiled_Gallery_Item {
3
	public $image;
4
5
	public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) {
6
		$this->image = $attachment_image;
7
		$this->grayscale = $grayscale;
0 ignored issues
show
Bug introduced by
The property grayscale does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
8
9
		$this->image_title = $this->image->post_title;
0 ignored issues
show
Bug introduced by
The property image_title does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
10
11
		$this->image_alt = get_post_meta( $this->image->ID, '_wp_attachment_image_alt', true );
0 ignored issues
show
Bug introduced by
The property image_alt does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
		// If no Alt value, use the caption
13 View Code Duplication
		if ( empty( $this->image_alt ) && ! empty( $this->image->post_excerpt ) ) {
14
			$this->image_alt = trim( strip_tags( $this->image->post_excerpt ) );
15
		}
16
		// If still no Alt value, use the title
17 View Code Duplication
		if ( empty( $this->image_alt ) && ! empty( $this->image->post_title ) ) {
18
			$this->image_alt = trim( strip_tags( $this->image->post_title ) );
19
		}
20
21
		$this->orig_file = wp_get_attachment_url( $this->image->ID );
0 ignored issues
show
Bug introduced by
The property orig_file does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
		$this->link = $needs_attachment_link ? get_attachment_link( $this->image->ID ) : $this->orig_file;
0 ignored issues
show
Bug introduced by
The property link does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
24
		// If h and w are the same, there's a reasonably good chance the image will need cropping to avoid being stretched.
25
		$crop = $this->image->height == $this->image->width ? true : false;
26
		$this->img_src = jetpack_photon_url( $this->orig_file, array(
0 ignored issues
show
Bug introduced by
The property img_src does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
			'w'    => $this->image->width,
28
			'h'    => $this->image->height,
29
			'crop' => $crop
30
		) );
31
	}
32
33
	public function fuzzy_image_meta() {
34
		$meta = wp_get_attachment_metadata( $this->image->ID );
35
		$img_meta = ( ! empty( $meta['image_meta'] ) ) ? (array) $meta['image_meta'] : array();
36 View Code Duplication
		if ( ! empty( $img_meta ) ) {
37
			foreach ( $img_meta as $k => $v ) {
38
				if ( 'latitude' == $k || 'longitude' == $k )
39
					unset( $img_meta[$k] );
40
			}
41
		}
42
43
		return $img_meta;
44
	}
45
46
	public function meta_width() {
47
		$meta = wp_get_attachment_metadata( $this->image->ID );
48
		return isset( $meta['width'] ) ? intval( $meta['width'] ) : '';
49
	}
50
51
	public function meta_height() {
52
		$meta = wp_get_attachment_metadata( $this->image->ID );
53
		return isset( $meta['height'] ) ? intval( $meta['height'] ) : '';
54
	}
55
56
	public function medium_file() {
57
		$medium_file_info = wp_get_attachment_image_src( $this->image->ID, 'medium' );
58
		$medium_file      = isset( $medium_file_info[0] ) ? $medium_file_info[0] : '';
59
		return $medium_file;
60
	}
61
62
	public function large_file() {
63
		$large_file_info  = wp_get_attachment_image_src( $this->image->ID, 'large' );
64
		$large_file       = isset( $large_file_info[0] ) ? $large_file_info[0] : '';
65
		return $large_file;
66
	}
67
}
68
69
class Jetpack_Tiled_Gallery_Rectangular_Item extends Jetpack_Tiled_Gallery_Item {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
70
	public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) {
71
		parent::__construct( $attachment_image, $needs_attachment_link, $grayscale );
72
		$this->img_src_grayscale = jetpack_photon_url( $this->img_src, array( 'filter' => 'grayscale' ) );
0 ignored issues
show
Bug introduced by
The property img_src_grayscale does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property img_src does not seem to exist. Did you mean img_src_grayscale?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
73
74
		$this->size = 'large';
0 ignored issues
show
Bug introduced by
The property size does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
75
76
		if ( $this->image->width < 250 )
77
			$this->size = 'small';
78
	}
79
}
80
81
class Jetpack_Tiled_Gallery_Square_Item extends Jetpack_Tiled_Gallery_Item {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
82
	public function __construct( $attachment_image, $needs_attachment_link, $grayscale ) {
83
		parent::__construct( $attachment_image, $needs_attachment_link, $grayscale );
84
		$this->img_src_grayscale = jetpack_photon_url( $this->img_src, array( 'filter' => 'grayscale', 'resize' => array( $this->image->width, $this->image->height ) ) );
0 ignored issues
show
Bug introduced by
The property img_src_grayscale does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property img_src does not seem to exist. Did you mean img_src_grayscale?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
85
	}
86
}
87
88
class Jetpack_Tiled_Gallery_Circle_Item extends Jetpack_Tiled_Gallery_Square_Item {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
89
}
90