Completed
Push — master ( d21dd2...a23d9a )
by Beñat
8s
created

SocialNetworksWidget::widget()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 8.8571
cc 6
eloc 12
nc 32
nop 2
1
<?php
2
3
/*
4
 * This file is part of the WordPress Standard project.
5
 *
6
 * Copyright (c) 2015-2016 LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AppTheme\Widgets;
13
14
use LIN3S\WPFoundation\Widgets\Widget;
15
use Timber\Timber;
16
17
/**
18
 * Social network widget. Is fully manageable inside Wordpress administrator panel.
19
 * This is a little pretty example that you can do extending WPFoundation's Widget class.
20
 *
21
 * @author Gorka Laucirica <[email protected]>
22
 */
23
final class SocialNetworksWidget extends Widget
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function widget($args, $instance)
29
    {
30
        $data = [
31
            'beforeWidget' => $args['before_widget'],
32
            'afterWidget'  => $args['after_widget'],
33
            'beforeTitle'  => $args['before_title'],
34
            'afterTitle'   => $args['after_title'],
35
            'twitterUrl'   => (!empty($instance['twitterUrl'])) ? strip_tags($instance['twitterUrl']) : '',
36
            'facebookUrl'  => (!empty($instance['facebookUrl'])) ? strip_tags($instance['facebookUrl']) : '',
37
            'pinterestUrl' => (!empty($instance['pinterestUrl'])) ? strip_tags($instance['pinterestUrl']) : '',
38
            'youtubeUrl'   => (!empty($instance['youtubeUrl'])) ? strip_tags($instance['youtubeUrl']) : '',
39
            'rssUrl'       => (!empty($instance['rssUrl'])) ? strip_tags($instance['rssUrl']) : '',
40
        ];
41
42
        return Timber::render('widgets/front/socialNetworks.twig', $data);
0 ignored issues
show
Documentation introduced by
'widgets/front/socialNetworks.twig' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function form($instance)
49
    {
50
        $instance['widgetNumber'] = $this->number();
51
        $instance['widgetName'] = $this->name();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52
53
        return Timber::render('widgets/admin/socialNetworks.twig', $instance);
0 ignored issues
show
Documentation introduced by
'widgets/admin/socialNetworks.twig' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function update($newInstance)
60
    {
61
        $instance = [
62
            'twitterUrl'   => (!empty($newInstance['twitterUrl'])) ? strip_tags($newInstance['twitterUrl']) : '',
63
            'facebookUrl'  => (!empty($newInstance['facebookUrl'])) ? strip_tags($newInstance['facebookUrl']) : '',
64
            'pinterestUrl' => (!empty($newInstance['pinterestUrl'])) ? strip_tags($newInstance['pinterestUrl']) : '',
65
            'youtubeUrl'   => (!empty($newInstance['youtubeUrl'])) ? strip_tags($newInstance['youtubeUrl']) : '',
66
            'rssUrl'       => (!empty($newInstance['rssUrl'])) ? strip_tags($newInstance['rssUrl']) : '',
67
        ];
68
69
        return $instance;
70
    }
71
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
72