Completed
Push — develop ( 613db1...73b4e9 )
by Daniel
05:02
created

swiper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 7
crap 2
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2018 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\content\blocks;
11
12
class swiper extends recent
13
{
14
	/** @var \blitze\sitemaker\services\util */
15
	protected $util;
16
17
	/** @var string */
18
	protected $tpl_name = 'swiper';
19
20
	/**
21
	 * Constructor
22
	 *
23
	 * @param \phpbb\config\db							$config				Config object
24
	 * @param \phpbb\language\language					$language			Language Object
25
	 * @param \blitze\content\services\types			$content_types		Content types object
26
	 * @param \blitze\content\services\fields			$fields				Content fields object
27
	 * @param \blitze\sitemaker\services\date_range		$date_range			Date Range Object
28
	 * @param \blitze\sitemaker\services\forum\data		$forum				Forum Data object
29
	 * @param \blitze\sitemaker\services\util			$util       		Sitemaker utility object
30
	 */
31
	public function __construct(\phpbb\config\db $config, \phpbb\language\language $language, \blitze\content\services\types $content_types, \blitze\content\services\fields $fields, \blitze\sitemaker\services\date_range $date_range, \blitze\sitemaker\services\forum\data $forum, \blitze\sitemaker\services\util $util)
32
	{
33
		parent::__construct($config, $language, $content_types, $fields, $date_range, $forum);
34
35
		$this->util = $util;
36
	}
37
38
	/**
39
	 * {@inheritdoc}
40
	 */
41
	public function get_config(array $settings)
42
	{
43
		$config = parent::get_config($settings);
44
45
		$direction_options = array('horizontal' => 'SWIPER_DIRECTION_HORIZONTAL', 'vertical' => 'SWIPER_DIRECTION_VERTICAL');
46
		$effect_options = array('slide' => 'SWIPER_EFFECT_SLIDE', 'fade' => 'SWIPER_EFFECT_FADE', 'coverflow' => 'SWIPER_EFFECT_COVERFLOW', 'flip' => 'SWIPER_EFFECT_FLIP');
47
		$pagination_options = array('' => 'SWIPER_PAGINATION_NONE', 'bullets' => 'SWIPER_PAGINATION_BULLETS', 'fraction' => 'SWIPER_PAGINATION_FRACTION', 'progressbar' => 'SWIPER_PAGINATION_PROGRESSBAR');
48
		$theme_options = array('default' => 'SWIPER_THEME_DEFAULT', 'white' => 'SWIPER_THEME_WHITE', 'black' => 'SWIPER_THEME_BLACK');
49
		$text_pos_options = array('top' => 'SWIPER_TEXT_POSITION_TOP', 'left' => 'SWIPER_TEXT_POSITION_LEFT', 'center' => 'SWIPER_TEXT_POSITION_CENTER', 'right' => 'SWIPER_TEXT_POSITION_RIGHT', 'bottom' => 'SWIPER_TEXT_POSITION_BOTTOM', 'after' => 'SWIPER_TEXT_POSITION_AFTER', 'random' => 'SWIPER_TEXT_POSITION_RANDOM');
50
51
		return array_merge($config, array(
1 ignored issue
show
Best Practice introduced by
The expression return array_merge($conf...rue, 'default' => 0))); seems to be an array, but some of its elements' types (array) are incompatible with the return type of the parent method blitze\content\blocks\recent::get_config of type array<string,string|arra...string,string|integer>>.

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 new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return '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...
52
			'layout'			=> '',
53
			'legend3'			=> 'SWIPER_SLIDESHOW',
54
				'navigation'		=> array('lang' => 'SWIPER_NAVIGATION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'default' => 1),
55
				'theme'				=> array('lang' => 'SWIPER_THEME', 'validate' => 'string', 'type' => 'select', 'options' => $theme_options, 'default' => ''),
56
				'pagination'		=> array('lang' => 'SWIPER_PAGINATION', 'validate' => 'string', 'type' => 'select', 'options' => $pagination_options, 'default' => 1),
57
				'effect'			=> array('lang' => 'SWIPER_EFFECT', 'validate' => 'string', 'type' => 'select', 'options' => $effect_options, 'default' => 'slide'),
58
				'parallax'			=> array('lang' => 'SWIPER_PARALLAX_IMAGE_URL', 'validate' => 'string', 'type' => 'text', 'default' => ''),
59
				'direction'			=> array('lang' => 'SWIPER_DIRECTION', 'validate' => 'string', 'type' => 'select:1:0:direction', 'options' => $direction_options, 'default' => 'horizontal', 'append' => '<div id="direction-vertical" class="error small">' . $this->language->lang('SWIPER_HEIGHT_REQUIRED') . '</div>'),
60
				'height'			=> array('lang' => 'SWIPER_HEIGHT', 'validate' => 'int:0', 'type' => 'number:0', 'default' => 0, 'append' => 'PIXEL'),
61
				'thumbs'			=> array('lang' => 'SWIPER_THUMBNAILS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'default' => 0),
62
				'loop'				=> array('lang' => 'SWIPER_LOOP', 'validate' => 'bool', 'type' => 'radio:yes_no', 'default' => 1),
63
				'autoplay'			=> array('lang' => 'SWIPER_AUTOPLAY', 'validate' => 'int:0', 'type' => 'number:0', 'default' => 0, 'append' => 'MILLISECONDS'),
64
			'legend4'			=> 'SWIPER_SLIDES',
65
				'text_position'		=> array('lang' => 'SWIPER_TEXT_POSITION', 'validate' => 'string', 'type' => 'select', 'options' => $text_pos_options, 'default' => ''),
66
				'slides-per-view'	=> array('lang' => 'SWIPER_SLIDES_PER_VIEW', 'validate' => 'int:1', 'type' => 'number:1', 'default' => 1),
67
				'slides-per-group'	=> array('lang' => 'SWIPER_SLIDES_PER_GROUP', 'validate' => 'int:1', 'type' => 'number:1', 'default' => 1),
68
				'space-between'		=> array('lang' => 'SWIPER_SPACE_BETWEEN_SLIDES', 'validate' => 'int:0', 'type' => 'number:0', 'default' => 10, 'append' => 'PIXEL'),
69
				'set-wrapper-size'	=> array('lang' => 'SWIPER_EQUAL_HEIGHT_SLIDES', 'validate' => 'bool', 'type' => 'radio:yes_no', 'default' => 1),
70
				'auto-height'		=> array('lang' => 'SWIPER_AUTO_HEIGHT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'default' => 0),
71
				'centered-slides'	=> array('lang' => 'SWIPER_CENTERED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'default' => 0),
72
				'free-mode'			=> array('lang' => 'SWIPER_FREE_MODE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0),
73
		));
74
	}
75
76
	/**
77
	 * {@inheritdoc}
78
	 */
79
	public function display(array $bdata, $edit_mode = false)
80
	{
81
		$this->util->add_assets(array(
82
			'js'   => array(
83
				'@blitze_content/vendor/swiper/dist/js/swiper.min.js',
84
				'@blitze_content/assets/blocks/swiper.min.js',
85
			),
86
			'css'   => array(
87
				'@blitze_content/assets/blocks/swiper.min.css',
88
			)
89
		));
90
91
		$this->ptemplate->assign_vars(array(
92
			'ID'			=> $bdata['bid'],
93
			'SETTINGS'		=> $bdata['settings'],
94
		));
95
96
		return parent::display($bdata, $edit_mode);
97
	}
98
}
99