@@ -50,6 +50,7 @@ function showHelp(): void
5050 -p, --path=PATH Path to scan (required).
5151 --exclude=LIST Comma-separated paths to exclude.
5252 --exclude-rules=LIST Comma-separated rule IDs to ignore.
53+ --list-rules Show all available rule IDs.
5354 --help Show this help message.
5455
5556 Examples:
@@ -93,6 +94,37 @@ function outputResults(array $results): void
9394 echo "Summary: Scanned {$ scannedCount } files, found {$ issueCount } potential issues. \n" ;
9495}
9596
97+ /**
98+ * Fetches and displays all available security rule IDs (CIS and OWASP).
99+ *
100+ * @return void Outputs directly to STDOUT
101+ */
102+ function listRules (): void
103+ {
104+ // The rules classes must be fully loaded via the autoloader by this point.
105+ $ cisRules = Yousha \PhpSecurityLinter \Rules \CisRules::getRules ();
106+ $ owaspRules = Yousha \PhpSecurityLinter \Rules \OwaspRules::getRules ();
107+ $ allRules = array_merge ($ cisRules , $ owaspRules );
108+ echo "Available Rule IDs \n" ;
109+ echo str_repeat ("= " , 40 ) . "\n\n" ;
110+ // Sort by ID for easier reading.
111+ usort ($ allRules , fn ($ a , $ b ): int => strcmp ((string ) $ a ['id ' ], (string ) $ b ['id ' ]));
112+
113+ foreach ($ allRules as $ rule ) {
114+ $ severity = strtoupper ((string ) $ rule ['severity ' ]);
115+ $ id = $ rule ['id ' ];
116+ $ message = str_replace ([$ id . ': ' , $ id . ': ' ], ['' , '' ], $ rule ['message ' ]);
117+ echo sprintf (
118+ "[%s] %s: %s \n" ,
119+ $ severity ,
120+ $ id ,
121+ $ message
122+ );
123+ }
124+
125+ echo "\nTotal rules: " . count ($ allRules ) . "\n" ;
126+ }
127+
96128function runCli (array $ argv ): int
97129{
98130 $ shortOpts = 'p: ' ;
@@ -101,6 +133,7 @@ function runCli(array $argv): int
101133 'exclude: ' ,
102134 'exclude-rules: ' ,
103135 'help ' ,
136+ 'list-rules ' ,
104137 ];
105138 $ options = getopt ($ shortOpts , $ longOpts );
106139
@@ -109,6 +142,12 @@ function runCli(array $argv): int
109142 return 0 ;
110143 }
111144
145+ // Check for --list-rules
146+ if (isset ($ options ['list-rules ' ])) {
147+ listRules ();
148+ return 0 ;
149+ }
150+
112151 // Validate path.
113152 $ path = $ options ['p ' ] ?? $ options ['path ' ] ?? null ;
114153
0 commit comments