referencesNewreferenceAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 43.75 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 21
loc 48
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerEvents() 21 24 1
A fireNewReference() 0 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * ****************************************************************************
4
 * references - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 *
14
 * @copyright       Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
15
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
16
 * @package         references
17
 * @author          Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
18
 *
19
 * ****************************************************************************
20
 */
21
22
/**
23
 * Plugin chargé de notifier de la création d'une nouvelle catégorie
24
 *
25
 */
26
class referencesNewreferenceAction extends references_action
27
{
28 View Code Duplication
    public function registerEvents()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        /**
31
         * La liste des évènements traités par le plugin se présente sous la forme d'un tableau compposé comme ceci :
32
         *
33
         * Indice   Signification
34
         * ----------------------
35
         *    0        Evènement sur lequel se raccrocher (voir class/references_plugins.php::EVENT_ON_PRODUCT_CREATE
36
         *    1        Priorité du plugin (de 1 à 5)
37
         *    2        Script Php à inclure
38
         *    3        Classe à instancier
39
         *    4        Méthode à appeler
40
         */
41
        $events   = array();
42
        $events[] = array(
43
            references_plugins::EVENT_ON_REFERENCE_CREATE,
44
            references_plugins::EVENT_PRIORITY_1,
45
            basename(__FILE__),
46
            __CLASS__,
47
            'fireNewReference'
48
        );
49
50
        return $events;
51
    }
52
53
    /**
54
     * Méthode appelée pour indiquer qu'une nouvelle référence a été créée
55
     *
56
     * @param object $parameters La référence qui vient d'être publiée
57
     * @return void
58
     */
59
    public function fireNewReference($parameters)
60
    {
61
        $article              = $parameters['reference'];
62
        $notification_handler = xoops_getHandler('notification');
63
        $articleForTemplate   = array();
64
        $originalArticle      = $article->toArray('n');
65
66
        foreach ($originalArticle as $key => $value) {
67
            @$articleForTemplate[strtoupper($key)] = strip_tags($value);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
68
        }
69
        $articleForTemplate['REFERENCES_URL']     = $article->getUrl();
70
        $articleForTemplate['ARTICLE_SHORT_TEXT'] = references_utils::truncate_tagsafe($article->getVar('article_text'), REFERENCES_SHORTEN_TEXT);
71
        $notification_handler->triggerEvent('global', 0, 'new_article', $articleForTemplate);
72
    }
73
}
74