PageWithImageFolder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getImagesForSeo() 0 11 3
A getLinksForSeo() 0 3 1
1
<?php
2
/**
3
* Defines the SupportingProjectPage page type - initial code created by ss generator
4
*/
5
class PageWithImageFolder extends PageWithImage implements SeoInformationProvider {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
7
	//static $allowed_children = array('PageWithImage', 'NearestPOIPage', 'OpenWeatherMapStationsPage','POIMapPage');
8
9
10
11
	public function getImagesForSeo() {
12
		$result = new ArrayList();
13
		$pwis = $this->owner->AllChildren()->where("ClassName in (
14
			'PageWithImage','PageWithImagesFolder')");
15
		foreach ($pwis->getIterator() as $pwi) {
16
			if ($pwi->MainImageID > 0) {
17
				$result->push($pwi->MainImage());
18
			}
19
		}
20
		return $result;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $result; (ArrayList) is incompatible with the return type declared by the interface SeoInformationProvider::getImagesForSeo of type DataList.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
21
	}
22
23
24
	public function getLinksForSeo() {
25
		return false;
26
	}
27
28
}
29
30
class PageWithImageFolder_Controller extends PageWithImage_Controller {
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...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
31
32
}
33