Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums do not have side effects #95

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
}
Loading