Skip to content

Commit

Permalink
Fix incorrect usage of "amount" instead of "number". (#1842)
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisCarden authored Sep 17, 2024
1 parent 6b04399 commit c9b9c39
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .travis/verify-discovered-values-cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$fileContent = file_get_contents($file->getPathname());
preg_match_all('/([ ]+)(final[ ]+)?[a-z<>]+[ ]+([a-z]+)[ ]+=\s+PossibleValuesDiscoveryUtil\s*\.\s*discover\(/ims', $fileContent, $discovery);
if ($discovery[0] !== []) {
/* match amount of calls */
/* match number of calls */
preg_match_all('/([ ]+)('.implode('|', $discovery[3]).')\.clear\(/ims', $fileContent, $clearing);
if (count($discovery[0]) !== count($clearing[0])) {
$missingClear []= $file->getFilename();
Expand Down
2 changes: 1 addition & 1 deletion docs/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Php Inspections (EA Extended) friendly way:
## If-return-return could be simplified

The inspection finds places where conditional return-statements can be simplified (by Quick-Fixing), reducing code
complexity metrics and amount of maintainable codebase.
complexity metrics and size of maintainable codebase.

```php
/* before */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class PrintfScanfArgumentsInspector extends BasePhpInspection {
private static final String messagePattern = "Pattern seems to be not valid.";
private static final String messageParameters = "Amount of expected parameters is %c%.";
private static final String messageParameters = "Number of expected parameters is %c%.";

@NotNull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public String getDisplayName() {

private static final Map<String, Integer> functionsRequirements = new HashMap<>();
static {
/* function name => amount of arguments considered legal */
/* function name => number of arguments considered legal */
functionsRequirements.put("debug_print_backtrace", -1);
functionsRequirements.put("debug_zval_dump", -1);
functionsRequirements.put("phpinfo", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

public class CascadingDirnameCallsInspector extends BasePhpInspection {
private static final String messagePattern = "'%e%' can be used instead (reduces amount of calls).";
private static final String messagePattern = "'%e%' can be used instead (reduces number of calls).";

@NotNull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void visitPhpMethod(@NotNull Method method) {
return;
}

/* ensure parent, parent methods are existing and contains the same amount of expressions */
/* ensure parent, parent methods are existing and contains the same number of expressions */
final PhpClass parent = OpenapiResolveUtil.resolveSuperClass(clazz);
final Method parentMethod = null == parent ? null : OpenapiResolveUtil.resolveMethod(parent, method.getName());
if (parentMethod == null || parentMethod.isAbstract() || parentMethod.isDeprecated() || parentMethod.getModifier().isPrivate()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void visitPhpClass(@NotNull PhpClass clazz) {
final Method nestedMethod = (Method) referenceResolved;
final Parameter[] parentParameters = nestedMethod.getParameters();

/* verify amount of parameters, visibility, static, abstract, final */
/* verify number of parameters, visibility, static, abstract, final */
if (
parentParameters.length == methodParameters.length &&
nestedMethod.isAbstract() == method.isAbstract() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void visitPhpDocTag(@NotNull PhpDocTag tag)
public void visitPhpShellCommand(@NotNull PhpShellCommandExpression expression) {}
public void visitPhpThrowExpression(@NotNull PhpThrowExpression expression) {}

/* overrides to reduce amount of 'com.jetbrains.php.lang.psi.visitors.PhpElementVisitor.visitElement' calls */
/* overrides to reduce number of 'com.jetbrains.php.lang.psi.visitors.PhpElementVisitor.visitElement' calls */
@Override public void visitPhpFile(PhpFile PhpFile) {}
@Override public void visitWhiteSpace(PsiWhiteSpace space) {}

Expand Down
8 changes: 4 additions & 4 deletions testData/fixtures/api/cascade-dirname.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

<warning descr="[EA] 'dirname(__DIR__, 3)' can be used instead (reduces amount of calls).">dirname(dirname(dirname(__DIR__)))</warning>;
<warning descr="[EA] 'dirname(trim(__DIR__), 3)' can be used instead (reduces amount of calls).">dirname(dirname(dirname(trim(__DIR__))))</warning>;
<warning descr="[EA] 'dirname(__DIR__, 1 + $level)' can be used instead (reduces amount of calls).">dirname(dirname(__DIR__, $level))</warning>;
<warning descr="[EA] 'dirname(__DIR__, 3)' can be used instead (reduces amount of calls).">dirname(dirname(__DIR__, 1), 2)</warning>;
<warning descr="[EA] 'dirname(__DIR__, 3)' can be used instead (reduces number of calls).">dirname(dirname(dirname(__DIR__)))</warning>;
<warning descr="[EA] 'dirname(trim(__DIR__), 3)' can be used instead (reduces number of calls).">dirname(dirname(dirname(trim(__DIR__))))</warning>;
<warning descr="[EA] 'dirname(__DIR__, 1 + $level)' can be used instead (reduces number of calls).">dirname(dirname(__DIR__, $level))</warning>;
<warning descr="[EA] 'dirname(__DIR__, 3)' can be used instead (reduces number of calls).">dirname(dirname(__DIR__, 1), 2)</warning>;

/* false-positives */
dirname(realpath(__DIR__), 2);
Expand Down
20 changes: 10 additions & 10 deletions testData/fixtures/api/printf-scanf.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ public function check($arg, $handle) {
$pattern6 = '%*s %s';

/* all function reported */
echo <error descr="[EA] Amount of expected parameters is 3.">printf</error> ($pattern4, $arg);
echo <error descr="[EA] Amount of expected parameters is 3.">sprintf</error> ($pattern4, $arg);
echo <error descr="[EA] Amount of expected parameters is 4.">fprintf</error> ($handle, $pattern4, $arg);
echo <error descr="[EA] Amount of expected parameters is 4.">sscanf</error> ($arg, $pattern4, $arg);
echo <error descr="[EA] Amount of expected parameters is 4.">fscanf</error> ($handle, $pattern4, $arg);
echo <error descr="[EA] Number of expected parameters is 3.">printf</error> ($pattern4, $arg);
echo <error descr="[EA] Number of expected parameters is 3.">sprintf</error> ($pattern4, $arg);
echo <error descr="[EA] Number of expected parameters is 4.">fprintf</error> ($handle, $pattern4, $arg);
echo <error descr="[EA] Number of expected parameters is 4.">sscanf</error> ($arg, $pattern4, $arg);
echo <error descr="[EA] Number of expected parameters is 4.">fscanf</error> ($handle, $pattern4, $arg);

/* sscanf/fscanf with partially provided containers */
list($first, $second) = <error descr="[EA] Amount of expected parameters is 4.">sscanf</error> ($arg, $pattern4, $first);
list($first, $second) = <error descr="[EA] Amount of expected parameters is 4.">fscanf</error> ($handle, $pattern4, $first);
list($first, $second) = <error descr="[EA] Number of expected parameters is 4.">sscanf</error> ($arg, $pattern4, $first);
list($first, $second) = <error descr="[EA] Number of expected parameters is 4.">fscanf</error> ($handle, $pattern4, $first);

/* test resolving string literal */
echo <error descr="[EA] Amount of expected parameters is 3.">sprintf</error> (self::PATTERN1, $arg);
echo <error descr="[EA] Amount of expected parameters is 3.">sprintf</error> (self::$pattern2, $arg);
echo <error descr="[EA] Amount of expected parameters is 3.">sprintf</error> ($this->pattern3, $arg);
echo <error descr="[EA] Number of expected parameters is 3.">sprintf</error> (self::PATTERN1, $arg);
echo <error descr="[EA] Number of expected parameters is 3.">sprintf</error> (self::$pattern2, $arg);
echo <error descr="[EA] Number of expected parameters is 3.">sprintf</error> ($this->pattern3, $arg);
echo sprintf(<error descr="[EA] Pattern seems to be not valid.">'%'</error>, $arg);


Expand Down
2 changes: 1 addition & 1 deletion testData/fixtures/lang/variable-functions-php53.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/*
TODO: (configurable) call_user_func's first parameter validation
TODO: (configurable) amount of arguments validation for resolved methods/functions
TODO: (configurable) number of arguments validation for resolved methods/functions
*/

class ClassVFParent {
Expand Down

0 comments on commit c9b9c39

Please sign in to comment.