Skip to content

Enhancement: Extract phpweb\Spam\Challenge - #664

Closed
localheinz wants to merge 1 commit into
php:masterfrom
localheinz:feature/spam-challenge
Closed

Enhancement: Extract phpweb\Spam\Challenge#664
localheinz wants to merge 1 commit into
php:masterfrom
localheinz:feature/spam-challenge

Conversation

@localheinz

Copy link
Copy Markdown
Contributor

This pull request

  • extracts phpweb\Spam\Challenge

@localheinz
localheinzforce-pushed the feature/spam-challenge branch from a076df1 to dedb915CompareJuly 15, 2022 15:24
Comment threadsrc/Spam/Challenge.php Outdated

@kamil-tekielakamil-tekiela left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this. It helps with the readability a lot.

I am not a fan of static methods though. They make sense for create and isValidAnswer but everything else doesn't really need to be a public static method. I believe that we should test all public method with a dedicated test if possible. In this case, we don't access these methods from anywhere else outside the scope of the class.

I would also encourage you to specify all parameter and return types. This should also allow you to change $strict to true.

Comment threadsrc/Spam/Challenge.php Outdated
Comment on lines +106 to +83
$a = rand(0, 9);
$argumentOne = self::NUM[$a];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One-letter variable names aren't very good. Would you be able to come up with more descriptive name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay here (besides the variables are local, they're only used in the next statement). Although, we could inline the rand() call, and drop $a altogether (probably not a good for $b below).

Comment threadsrc/Spam/Challenge.php Outdated
Comment on lines +161 to +183
public static function plus($a, $b) {
return $a + $b;
}

public static function gen_plus($a) {
return rand(0, 9 - $a);
}

public static function minus($a, $b) {
return $a - $b;
}

public static function gen_minus($a) {
return rand(0, $a);
}

public static function print_infix($name, $a, $b) {
return "$a $name $b";
}

public static function print_prefix($name, $a, $b) {
return "$name($a, $b)";
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These do not need to be public or even static (except minus and plus). Could you make them all instance methods and then call them from the getters or from the constructor?

Comment threadsrc/Spam/Challenge.php Outdated
Comment threadsrc/Spam/Challenge.php Outdated
@localheinz
localheinz marked this pull request as draft July 16, 2022 12:10
@localheinz
localheinzforce-pushed the feature/spam-challenge branch 8 times, most recently from 22bb34e to 05aef42CompareDecember 7, 2023 15:17
@localheinzlocalheinz mentioned this pull request Dec 7, 2023
1 task
@localheinz
localheinzforce-pushed the feature/spam-challenge branch from 05aef42 to a88faf2CompareDecember 14, 2023 11:12
@github-actions

Copy link
Copy Markdown
Contributor

@localheinz
localheinz deleted the feature/spam-challenge branch February 12, 2024 16:50
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@localheinz@cmb69@kamil-tekiela@saundefined