good.php in Coder 8.3
File
tests/DrupalPractice/good/good.php
View source
<?php
$form['vocab_fieldset']['entity_view_modes'] = array(
'#type' => 'select',
'#prefix' => '<div id="entity_view_modes_div">',
'#suffix' => '</div>',
'#title' => t('View Mode'),
'#description' => '<p>' . t('test description') . '</p>',
'#required' => 1,
'#options' => array(),
'#ajax' => array(
'callback' => 'custom_listing_pages_entity_vocabulary_listing',
'wrapper' => 'vocab_fieldset_div',
'method' => 'replace',
'effect' => 'fade',
),
);
print_r($form);
function test1() {
$array = array(
1,
2,
);
foreach ($array as $key => $value) {
print $key;
}
try {
print 'foo';
} catch (Exception $e) {
print 'error';
}
$items['foo'] = 'bar';
return $items;
}
function test2() {
$list =& some_other_function();
$list = array();
}
function test3(&$variables, $hook) {
foreach ($variables['items'] as &$item) {
$item['image'] = 'foo';
}
}
function test4() {
global $user;
$x = 5;
if ($x == 5) {
$user = 123;
}
}
trait LangcodeTrait {
protected $langcode;
protected $lang;
public function setLangcode($langcode) {
$this->langcode = $langcode;
$this->lang = \Drupal::languageManager()
->getLanguage($this->langcode);
return $this;
}
public function getLangcode() {
if (!isset($this->langcode)) {
$lang = \Drupal::languageManager()
->getCurrentLanguage();
$this
->setLangcode($lang
->getId());
}
return $this->langcode;
}
}
class ClosureTest extends TestCase {
public function getEntities($limit) {
$entities = array_map(function () {
return $this
->prophesize(EntityInterface::class)
->reveal();
}, range(1, $limit));
return $entities;
}
}
$clicks = array();
$places = array();
$debug = '';
enumerate_menu('primary', function ($item) use (&$places, &$debug, &$clicks) {
$pos = array_pop($places);
$n_clicks = 34 - $pos;
generateClicks($item['node'], $n_clicks);
$clicks[$item['mlid']] = $n_clicks;
$debug .= "\nLink {$item['node']->title} got {$n_clicks} clicks and should end on {$pos} place.";
});
class PrivateMethodTest {
private function usedAsCallback() {
return FALSE;
}
public function test() {
return array_filter(array(), [
$this,
'usedAsCallback',
]);
}
}
class StrictSchemaEnabled {
protected $strictConfigSchema = TRUE;
}
Functions
Name |
Description |
test1 |
Ignoring the array value in a foreach loop is OK. |
test2 |
Variables that are used by reference are allowed to not be read. |
test3 |
Variables that are used by reference are allowed to not be read. |
test4 |
Global variables that are used in ifs should not be flagged as unused. |
Classes
Traits
Name |
Description |
LangcodeTrait |
A trait containing helper methods for language handling. |