Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Extract phpweb\Spam\Challenge #664

Closed
wants to merge 1 commit into from

Conversation

localheinz
Copy link
Contributor

This pull request

  • extracts phpweb\Spam\Challenge

@localheinz localheinz force-pushed the feature/spam-challenge branch from a076df1 to dedb915 Compare July 15, 2022 15:24
src/Spam/Challenge.php Outdated Show resolved Hide resolved
Copy link
Member

@kamil-tekiela kamil-tekiela left a comment

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 on lines 106 to 83
$a = rand(0, 9);
$argumentOne = self::NUM[$a];
Copy link
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
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 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
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?

src/Spam/Challenge.php Outdated Show resolved Hide resolved
src/Spam/Challenge.php Outdated Show resolved Hide resolved
@localheinz localheinz marked this pull request as draft July 16, 2022 12:10
@localheinz localheinz force-pushed the feature/spam-challenge branch 8 times, most recently from 22bb34e to 05aef42 Compare December 7, 2023 15:17
@localheinz localheinz force-pushed the feature/spam-challenge branch from 05aef42 to a88faf2 Compare December 14, 2023 11:12
Copy link
Contributor

🚀 Deployed on https://web-php-pr-664.preview.thephp.foundation

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

Successfully merging this pull request may close these issues.

4 participants