1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * webtrees: online genealogy |
||
4 | * Copyright (C) 2018 webtrees development team |
||
5 | * This program is free software: you can redistribute it and/or modify |
||
6 | * it under the terms of the GNU General Public License as published by |
||
7 | * the Free Software Foundation, either version 3 of the License, or |
||
8 | * (at your option) any later version. |
||
9 | * This program is distributed in the hope that it will be useful, |
||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
12 | * GNU General Public License for more details. |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
15 | */ |
||
16 | namespace Fisharebest\Webtrees; |
||
17 | |||
18 | /** |
||
19 | * Defined in session.php |
||
20 | * |
||
21 | * @global Tree $WT_TREE |
||
22 | */ |
||
23 | global $WT_TREE; |
||
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
}
}
![]() |
|||
24 | |||
25 | use Fisharebest\Webtrees\Controller\BranchesController; |
||
26 | |||
27 | define('WT_SCRIPT_NAME', 'branches.php'); |
||
28 | require './includes/session.php'; |
||
29 | |||
30 | $controller = new BranchesController; |
||
31 | $controller |
||
32 | ->pageHeader() |
||
33 | ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) |
||
34 | ->addInlineJavascript('autocomplete();'); |
||
35 | |||
36 | ?> |
||
37 | <div id="branches-page"> |
||
38 | <h2 class="center"><?php echo $controller->getPageTitle(); ?></h2> |
||
39 | <form name="surnlist" id="surnlist" action="branches.php"> |
||
40 | <table class="facts_table width50"> |
||
41 | <tbody> |
||
42 | <tr> |
||
43 | <td class="descriptionbox"> |
||
44 | <?php echo GedcomTag::getLabel('SURN'); ?> |
||
45 | </td> |
||
46 | <td class="optionbox"> |
||
47 | <input data-autocomplete-type="SURN" type="text" name="surname" id="SURN" value="<?php echo Filter::escapeHtml($controller->getSurname()); ?>" dir="auto"> |
||
48 | <input type="hidden" name="ged" id="ged" value="<?php echo $WT_TREE->getNameHtml(); ?>"> |
||
49 | <input type="submit" value="<?php echo /* I18N: A button label. */ I18N::translate('view'); ?>"> |
||
50 | <p> |
||
51 | <?php echo I18N::translate('Phonetic search'); ?> |
||
52 | </p> |
||
53 | <p> |
||
54 | <input type="checkbox" name="soundex_std" id="soundex_std" value="1" <?php echo $controller->getSoundexStd() ? 'checked' : ''; ?>> |
||
55 | <label for="soundex_std"><?php echo I18N::translate('Russell'); ?></label> |
||
56 | <input type="checkbox" name="soundex_dm" id="soundex_dm" value="1" <?php echo $controller->getSoundexDm() ? 'checked' : ''; ?>> |
||
57 | <label for="soundex_dm"><?php echo I18N::translate('Daitch-Mokotoff'); ?></label> |
||
58 | </p> |
||
59 | </td> |
||
60 | </tr> |
||
61 | </tbody> |
||
62 | </table> |
||
63 | </form> |
||
64 | <ol> |
||
65 | <?php echo $controller->getPatriarchsHtml(); ?> |
||
66 | </ol> |
||
67 | </div> |
||
68 |
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.