These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * |
||
4 | * Module: Soapbox |
||
5 | * Version: v 1.5 |
||
6 | * Release Date: 23 August 2004 |
||
7 | * Author: hsalazar |
||
8 | * Licence: GNU |
||
9 | */ |
||
10 | |||
11 | use Xmf\Request; |
||
12 | |||
13 | include __DIR__ . '/header.php'; |
||
14 | global $moduleDirName; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
15 | $moduleDirName = $myts->htmlSpecialChars(basename(__DIR__)); |
||
16 | View Code Duplication | if ($moduleDirName !== 'soapbox' && $moduleDirName !== '' && !preg_match('/^(\D+)(\d*)$/', $moduleDirName)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
17 | echo('invalid dirname: ' . htmlspecialchars($moduleDirName, ENT_QUOTES)); |
||
18 | } |
||
19 | |||
20 | require_once XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/include/cleantags.php'; |
||
21 | |||
22 | $articleID = Request::getInt('$articleID', Request::getInt('$articleID', 0, 'POST'), 'GET'); |
||
23 | |||
24 | if (0 === $articleID) { |
||
25 | redirect_header('index.php'); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @param $articleID |
||
30 | */ |
||
31 | function PrintPage($articleID) |
||
0 ignored issues
–
show
PrintPage uses the super-global variable $GLOBALS which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
32 | { |
||
33 | global $moduleDirName; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
34 | global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
35 | $myts = MyTextSanitizer:: getInstance(); |
||
36 | $articleID = (int)$articleID; |
||
37 | //get entry object |
||
38 | $entrydataHandler = xoops_getModuleHandler('entryget', $moduleDirName); |
||
39 | $_entryob = $entrydataHandler->getArticleOnePermcheck($articleID, true, true); |
||
40 | View Code Duplication | if (!is_object($_entryob)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
41 | redirect_header(XOOPS_URL . '/modules/' . $moduleDirName . '/index.php', 1, 'Not Found'); |
||
42 | } |
||
43 | //------------------------------------- |
||
44 | $articles = $_entryob->toArray(); |
||
45 | //get category object |
||
46 | $_categoryob = $_entryob->_sbcolumns; |
||
47 | //get vars |
||
48 | $category = $_categoryob->toArray(); |
||
49 | //------------------------------------- |
||
50 | //get author |
||
51 | $authorname = SoapboxUtility::getAuthorName($category['author']); |
||
52 | //------------------------------------- |
||
53 | |||
54 | $datetime = $myts->htmlSpecialChars(formatTimestamp($articles['datesub'], $xoopsModuleConfig['dateformat'])); |
||
55 | // $lead = $myts->htmlSpecialChars($lead); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
59% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
56 | // $bodytext = str_replace("[pagebreak]","<br style=\"page-break-after:always;\">",$bodytext); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
53% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
57 | // $bodytext = $myts->displayTarea($bodytext, $html, $smiley, $xcodes, '', $breaks); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
58 | $bodytext = str_replace('[pagebreak]', '<br style="page-break-after:always;">', $_entryob->getVar('bodytext', 'none')); |
||
59 | $bodytext = $GLOBALS['SoapboxCleantags']->cleanTags($myts->displayTarea($bodytext, $articles['html'], $articles['smiley'], $articles['xcodes'], '', $articles['breaks'])); |
||
0 ignored issues
–
show
$bodytext is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
60 | |||
61 | $sitename = $myts->htmlSpecialChars($xoopsConfig['sitename']); |
||
62 | $slogan = $myts->htmlSpecialChars($xoopsConfig['slogan']); |
||
63 | |||
64 | echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n"; |
||
65 | echo "<html>\n<head>\n"; |
||
66 | echo '<title>' . $sitename . "</title>\n"; |
||
67 | echo "<meta http-equiv='Content-Type' content='text/html; charset=" . _CHARSET . "' />\n"; |
||
68 | echo "<meta name='AUTHOR' content='" . $sitename . "' />\n"; |
||
69 | echo "<meta name='COPYRIGHT' content='Copyright (c) 2004 by " . $sitename . "' />\n"; |
||
70 | echo "<meta name='DESCRIPTION' content='" . $slogan . "' />\n"; |
||
71 | echo "<meta name='GENERATOR' content='" . XOOPS_VERSION . "' />\n\n\n"; |
||
72 | |||
73 | //hack start 2003-3-18 by toshimitsu |
||
74 | //Column: --> _MD_SOAPBOX_COLUMNPRN , Author: --> _MD_SOAPBOX_AUTHORPRN |
||
75 | echo "<body bgcolor='#ffffff' text='#000000'> |
||
76 | <div style='width: 600px; border: 1px solid #000; padding: 20px;'> |
||
77 | <div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'><img src='" |
||
78 | . XOOPS_URL |
||
79 | . '/modules/' |
||
80 | . $xoopsModule->dirname() |
||
81 | . "/assets/images/sb_slogo.png' border='0' alt='' /><h2 style='margin: 0;'>" |
||
82 | . $articles['headline'] |
||
83 | . '</h2></div> |
||
84 | <div></div> |
||
85 | <div>' |
||
86 | . _MD_SOAPBOX_COLUMNPRN |
||
87 | . '<b>' |
||
88 | . $category['name'] |
||
89 | . "</b></div> |
||
90 | <div style='padding-bottom: 6px; border-bottom: 1px solid #ccc;'>" |
||
91 | . _MD_SOAPBOX_AUTHORPRN |
||
92 | . ' <b>' |
||
93 | . $authorname |
||
94 | . '</b></div> |
||
95 | <p>' |
||
96 | . $articles['lead'] |
||
97 | . '</p> |
||
98 | <p>' |
||
99 | . $articles['bodytext'] |
||
100 | . "</p> |
||
101 | <div style='padding-top: 12px; border-top: 2px solid #ccc;'><small><b>Published: </b> " |
||
102 | . $datetime |
||
103 | . '<br></div> |
||
104 | </div> |
||
105 | <br> |
||
106 | </body> |
||
107 | </html>'; |
||
108 | } |
||
109 | |||
110 | PrintPage($articleID); |
||
111 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.