Skip to content

Commit

Permalink
Enums do not have side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Feb 5, 2024
1 parent ec45d66 commit 525a457
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
10 changes: 8 additions & 2 deletions moodle/Sniffs/Files/MoodleInternalSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private function count_artifacts(File $file) {
$position = 0;
$counter = 0;
while ($position !== false) {
if ($position = $file->findNext([T_CLASS, T_INTERFACE, T_TRAIT], ($position + 1))) {
if ($position = $file->findNext([T_CLASS, T_INTERFACE, T_TRAIT, T_ENUM], ($position + 1))) {
$counter++;
}

Expand All @@ -316,7 +316,13 @@ private function count_artifacts(File $file) {
*/
private function code_changes_global_state(File $file, $start, $end) {
$tokens = $file->getTokens();
$symbols = [T_CLASS => T_CLASS, T_INTERFACE => T_INTERFACE, T_TRAIT => T_TRAIT, T_FUNCTION => T_FUNCTION];
$symbols = [
T_CLASS => T_CLASS,
T_INTERFACE => T_INTERFACE,
T_TRAIT => T_TRAIT,
T_FUNCTION => T_FUNCTION,
T_ENUM => T_ENUM,
];
$conditions = [T_IF => T_IF, T_ELSE => T_ELSE, T_ELSEIF => T_ELSEIF];

for ($i = $start; $i <= $end; $i++) {
Expand Down
11 changes: 11 additions & 0 deletions moodle/Tests/FilesMoodleInternalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public function test_moodle_files_moodleinternal_declare_ok() {
$this->verify_cs_results();
}

public function test_moodle_files_moodleinternal_enum_ok() {
$this->set_standard('moodle');
$this->set_sniff('moodle.Files.MoodleInternal');
$this->set_fixture(__DIR__ . '/fixtures/files/moodleinternal/enum_ok.php');

$this->set_errors([]);
$this->set_warnings([]);

$this->verify_cs_results();
}

public function test_moodle_files_moodleinternal_namespace_ok() {
$this->set_standard('moodle');
$this->set_sniff('moodle.Files.MoodleInternal');
Expand Down
29 changes: 29 additions & 0 deletions moodle/Tests/fixtures/files/moodleinternal/enum_ok.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Chart line.
*
* @package core
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
enum example: string {
case one = 'one';
case two = 'two';
case three = 'three';
}

0 comments on commit 525a457

Please sign in to comment.