Skip to content

Commit 81d58d3

Browse files
author
Mingsong Hu
committed
PHPDoc
1 parent 490050f commit 81d58d3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

DrupalSecurity/Sniffs/PHP/ZipExtractSniff.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public function process(File $phpcsFile, $stackPtr)
8585
$this->processObjectCall($phpcsFile, $stackPtr);
8686
}
8787

88+
/**
89+
* Handle static calls such as ZipArchive::extractTo().
90+
*/
8891
private function processStaticCall(File $phpcsFile, int $stackPtr): void
8992
{
9093
$tokens = $phpcsFile->getTokens();
@@ -112,6 +115,9 @@ private function processStaticCall(File $phpcsFile, int $stackPtr): void
112115
$this->addExtractWarning($phpcsFile, $methodPtr, $methodConfig);
113116
}
114117

118+
/**
119+
* Handle chained/object calls such as $zip->extractTo().
120+
*/
115121
private function processObjectCall(File $phpcsFile, int $stackPtr): void
116122
{
117123
$tokens = $phpcsFile->getTokens();
@@ -134,11 +140,17 @@ private function processObjectCall(File $phpcsFile, int $stackPtr): void
134140
}
135141
}
136142

143+
/**
144+
* Emit the configured warning for a matched method.
145+
*/
137146
private function addExtractWarning(File $phpcsFile, int $methodPtr, array $methodConfig): void
138147
{
139148
$phpcsFile->addWarning($methodConfig['message'], $methodPtr, $methodConfig['code']);
140149
}
141150

151+
/**
152+
* Resolve the fully qualified class name used in a static call.
153+
*/
142154
private function getClassName(File $phpcsFile, int $stackPtr): string
143155
{
144156
$tokens = $phpcsFile->getTokens();
@@ -152,6 +164,9 @@ private function getClassName(File $phpcsFile, int $stackPtr): string
152164
return implode('', $parts);
153165
}
154166

167+
/**
168+
* Map a class (direct or alias) to one of the sniff targets.
169+
*/
155170
private function identifyTarget(File $phpcsFile, string $className): ?string
156171
{
157172
$normalized = ltrim(strtolower($className), '\\');
@@ -175,6 +190,9 @@ private function identifyTarget(File $phpcsFile, string $className): ?string
175190
return null;
176191
}
177192

193+
/**
194+
* Fetch method metadata for the requested target method.
195+
*/
178196
private function getMethodConfig(array $targetConfig, string $methodName): ?array
179197
{
180198
$methodName = strtolower($methodName);
@@ -186,6 +204,8 @@ private function getMethodConfig(array $targetConfig, string $methodName): ?arra
186204
}
187205

188206
/**
207+
* Return all aliases referencing the given target within the file.
208+
*
189209
* @return array<int, string>
190210
*/
191211
private function getTargetAliases(File $phpcsFile, string $targetKey): array
@@ -211,6 +231,8 @@ private function getTargetAliases(File $phpcsFile, string $targetKey): array
211231
}
212232

213233
/**
234+
* Discover variables/properties instantiated from the target class.
235+
*
214236
* @return array{variables: string[], properties: string[]}
215237
*/
216238
private function getTargetVariables(File $phpcsFile, string $targetKey): array
@@ -261,6 +283,8 @@ private function getTargetVariables(File $phpcsFile, string $targetKey): array
261283
}
262284

263285
/**
286+
* Build a deduplicated list of class names (FQCN + aliases) for a target.
287+
*
264288
* @return array<int, string>
265289
*/
266290
private function buildClassNameAlternatives(File $phpcsFile, string $targetKey, string $fqn): array
@@ -273,6 +297,9 @@ private function buildClassNameAlternatives(File $phpcsFile, string $targetKey,
273297
return array_values(array_unique($names, SORT_STRING));
274298
}
275299

300+
/**
301+
* Collect import use statements for the current file.
302+
*/
276303
private function getImportUseStatements(File $phpcsFile): array
277304
{
278305
$filename = $phpcsFile->getFilename();
@@ -310,6 +337,9 @@ private function getImportUseStatements(File $phpcsFile): array
310337
return $this->importsCache[$filename] = $useStatements;
311338
}
312339

340+
/**
341+
* Determine if the variable/property before the operator is a tracked Zip instance.
342+
*/
313343
private function isTargetVariable(File $phpcsFile, int $stackPtr, string $targetKey): bool
314344
{
315345
$tokens = $phpcsFile->getTokens();

0 commit comments

Comments
 (0)