Skip to content

Commit 0d30c0b

Browse files
Copilotndrwnaguib
andcommitted
Add documentation and verification script for frankenstyle compliance
Co-authored-by: ndrwnaguib <24280372+ndrwnaguib@users.noreply.github.com>
1 parent 6f79b2b commit 0d30c0b

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

FRANKENSTYLE_CHANGES.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Frankenstyle Naming Compliance Changes
2+
3+
This document summarizes the changes made to comply with Moodle's frankenstyle naming conventions.
4+
5+
## Changes Made
6+
7+
### 1. Exception Class
8+
- **Old**: `onlinejudge_exception` (in `exceptions.php`)
9+
- **New**: `\local_onlinejudge\exception` (in `classes/exception.php`)
10+
11+
### 2. Judge Base Class
12+
- **Old**: `judge_base` (in `judgelib.php`)
13+
- **New**: `\local_onlinejudge\judge\base` (in `classes/judge/base.php`)
14+
15+
### 3. Judge Sandbox Class
16+
- **Old**: `judge_sandbox` (in `judge/sandbox/lib.php`)
17+
- **New**: `\local_onlinejudge\judge\sandbox` (in `classes/judge/sandbox.php`)
18+
19+
### 4. Judge Sphere Engine Class
20+
- **Old**: `judge_sphere_engine` (in `judge/sphere_engine/lib.php`)
21+
- **New**: `\local_onlinejudge\judge\sphere_engine` (in `classes/judge/sphere_engine.php`)
22+
23+
### 5. Event Class
24+
- **Old**: `onlinejudge_task_judged` (in `classes/event/onlinejudge_task_judged.php`)
25+
- **New**: `task_judged` (in `classes/event/task_judged.php`)
26+
- **Namespace**: Changed from `mod_onlinejudge\event` to `local_onlinejudge\event`
27+
28+
## Backward Compatibility
29+
30+
To ensure existing code continues to work, backward compatibility aliases have been added in `judgelib.php`:
31+
32+
```php
33+
// Backward compatibility aliases
34+
if (!class_exists('onlinejudge_exception')) {
35+
class_alias('\\local_onlinejudge\\exception', 'onlinejudge_exception');
36+
}
37+
if (!class_exists('judge_base')) {
38+
class_alias('\\local_onlinejudge\\judge\\base', 'judge_base');
39+
}
40+
if (!class_exists('judge_sandbox')) {
41+
class_alias('\\local_onlinejudge\\judge\\sandbox', 'judge_sandbox');
42+
}
43+
if (!class_exists('judge_sphere_engine')) {
44+
class_alias('\\local_onlinejudge\\judge\\sphere_engine', 'judge_sphere_engine');
45+
}
46+
```
47+
48+
## Files Structure
49+
50+
The new frankenstyle-compliant structure is:
51+
52+
```
53+
classes/
54+
├── exception.php # \local_onlinejudge\exception
55+
├── judge/
56+
│ ├── base.php # \local_onlinejudge\judge\base
57+
│ ├── sandbox.php # \local_onlinejudge\judge\sandbox
58+
│ └── sphere_engine.php # \local_onlinejudge\judge\sphere_engine
59+
└── event/
60+
└── task_judged.php # \local_onlinejudge\event\task_judged
61+
```
62+
63+
## Migration Guide
64+
65+
### For New Code
66+
Use the new namespaced classes:
67+
```php
68+
// Use this
69+
use local_onlinejudge\exception;
70+
use local_onlinejudge\judge\base;
71+
use local_onlinejudge\judge\sandbox;
72+
use local_onlinejudge\judge\sphere_engine;
73+
use local_onlinejudge\event\task_judged;
74+
```
75+
76+
### For Existing Code
77+
No changes required - old class names will continue to work due to backward compatibility aliases.
78+
79+
## Language Strings
80+
81+
Added new language strings for the renamed event:
82+
- `event_task_judged` - "Online Judge Task Judged"
83+
- `event_task_judged_description` - "The event is fired when an online judge task has been judged."
84+
85+
## Benefits
86+
87+
1. **Compliance**: Meets Moodle's frankenstyle naming requirements for plugin database approval
88+
2. **Autoloading**: Classes can be autoloaded using Moodle's class loader
89+
3. **Namespace**: Proper namespace organization prevents naming conflicts
90+
4. **Maintainability**: Clear class organization in the `classes/` directory
91+
5. **Compatibility**: Existing code continues to work without modification
92+
93+
## Notes
94+
95+
- The old files in `judge/` directory are still present for backward compatibility
96+
- All functions in `judgelib.php` retain their original names (they follow correct naming)
97+
- The plugin continues to work exactly as before with no functional changes

verify_frankenstyle.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env php
2+
<?php
3+
/**
4+
* Verification script for frankenstyle naming compliance
5+
*
6+
* This script verifies that all classes have correct syntax
7+
* and that the file structure is properly organized.
8+
*/
9+
10+
$basedir = dirname(__FILE__);
11+
12+
echo "Verifying frankenstyle naming compliance...\n";
13+
14+
// Check if all new class files exist
15+
$newClassFiles = [
16+
'classes/exception.php',
17+
'classes/judge/base.php',
18+
'classes/judge/sandbox.php',
19+
'classes/judge/sphere_engine.php',
20+
'classes/event/task_judged.php'
21+
];
22+
23+
echo "\n1. Checking file existence:\n";
24+
foreach ($newClassFiles as $file) {
25+
$fullPath = $basedir . '/' . $file;
26+
if (file_exists($fullPath)) {
27+
echo "$file exists\n";
28+
} else {
29+
echo "$file missing\n";
30+
}
31+
}
32+
33+
// Check syntax of all new files
34+
echo "\n2. Checking syntax:\n";
35+
foreach ($newClassFiles as $file) {
36+
$fullPath = $basedir . '/' . $file;
37+
if (file_exists($fullPath)) {
38+
$output = [];
39+
$return = 0;
40+
exec("php -l " . escapeshellarg($fullPath), $output, $return);
41+
if ($return === 0) {
42+
echo "$file has valid syntax\n";
43+
} else {
44+
echo "$file has syntax errors\n";
45+
echo " " . implode("\n ", $output) . "\n";
46+
}
47+
}
48+
}
49+
50+
// Check that judgelib.php loads properly
51+
echo "\n3. Checking main library file:\n";
52+
$output = [];
53+
$return = 0;
54+
exec("php -l " . escapeshellarg($basedir . '/judgelib.php'), $output, $return);
55+
if ($return === 0) {
56+
echo "✓ judgelib.php has valid syntax\n";
57+
} else {
58+
echo "✗ judgelib.php has syntax errors\n";
59+
echo " " . implode("\n ", $output) . "\n";
60+
}
61+
62+
// Check that language file has proper structure
63+
echo "\n4. Checking language strings:\n";
64+
$langFile = $basedir . '/lang/en/local_onlinejudge.php';
65+
if (file_exists($langFile)) {
66+
$content = file_get_contents($langFile);
67+
if (strpos($content, 'event_task_judged') !== false) {
68+
echo "✓ New event language strings found\n";
69+
} else {
70+
echo "✗ New event language strings missing\n";
71+
}
72+
} else {
73+
echo "✗ Language file missing\n";
74+
}
75+
76+
// Check file structure
77+
echo "\n5. Checking directory structure:\n";
78+
$requiredDirs = ['classes', 'classes/judge', 'classes/event'];
79+
foreach ($requiredDirs as $dir) {
80+
$fullPath = $basedir . '/' . $dir;
81+
if (is_dir($fullPath)) {
82+
echo "✓ Directory $dir exists\n";
83+
} else {
84+
echo "✗ Directory $dir missing\n";
85+
}
86+
}
87+
88+
echo "\nVerification complete!\n";
89+
echo "If all checks show ✓, the frankenstyle naming compliance is properly implemented.\n";

0 commit comments

Comments
 (0)