Skip to content

Suggestion for keeping an consistent, automatic code style (with php-cs-fixer) - #92

Open
pscheit wants to merge 4 commits into
hamcrest:masterfrom
pscheit:php-cs-fixer
Open

Suggestion for keeping an consistent, automatic code style (with php-cs-fixer)#92
pscheit wants to merge 4 commits into
hamcrest:masterfrom
pscheit:php-cs-fixer

Conversation

@pscheit

@pscheit pscheit commented Jun 25, 2025

Copy link
Copy Markdown
Contributor

I noticed a few comments about Codestyle in PRs.
To keep maintainer and contributors happy, I'd suggest to automate the codestyle. That way everyone can concentrate on the code(quality) and not on the codestyle.

Of course a code-formatter does not everything 1000% the way one wants. It's just not customizable entirely.

However this leads to a more consistent codestyle (thats why PSR-x was born) throughout different projects - which I think is a good thing.

Used:
https://cs.symfony.com/doc/usage.html

Cause I feel like this has become a defactor-standard.

Based it on PSR-12, but a lot needs customization.
Non "standard" are in this repo:

  • the blank line after the opening class brace
  • the location of the namespace
  • the indentation from chained method calls (this looks almost broken in places?)

Anyway, this is just a suggestion, happy to adjust whatever you want (and we can).

Would probably add this to the pipeline, because otherwise no one runs this, and WHEN someone runs it and wants to contribute everything would be outdated.

Of course we can disable the method chaining rules and leave it in "free"-mode as is right now.

Hope you like it!

Comment on lines 72 to +74
$mismatchDescription->appendText('element ')->appendValue($k)
->appendText(' was ')->appendValue($actual[$k]);
->appendText(' was ')->appendValue($actual[$k])
;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would probably write it more like:

      $mismatchDescription
          ->appendText('element ')
          ->appendValue($k)
          ->appendText(' was ')
          ->appendValue($actual[$k])
    ;

Comment on lines 57 to +60
$description
->appendText('array with key ')
->appendDescriptionOf($this->_keyMatcher)
;
->appendText('array with key ')
->appendDescriptionOf($this->_keyMatcher)
;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this looks more concise to me!

Comment on lines 41 to +43
$mismatchDescription->appendText('array was ')
->appendText('[')
;
->appendText('[')
;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

     $mismatchDescription
         ->appendText('array was ')
         ->appendText('[')
     ;

* @param mixed $item the object against which the matcher is evaluated.
*
* @return boolean <code>true</code> if <var>$item</var> matches,
* @return bool <code>true</code> if <var>$item</var> matches,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

up for discussion of course, i like it more if its concise (but dont care if its boolean or bool)


public function testMatchesArrayContainingKey()
{
$array = array('a'=>1, 'b'=>2, 'c'=>3);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thought about this a lot, but actually Hamcrest itself describes array's with => (with whitespace around the operator) and this is PSR- standard, so would change that

{
assertThat((float) 5.2, floatValue());
assertThat((double) 5.3, doubleValue());
assertThat((float) 5.3, doubleValue());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is no difference in PHP. float, double or real are the same datatype.

At the C level, everything is stored as a double.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

But 'double' is going to be deprecated in PHP 8.6.

@aik099

aik099 commented Jul 30, 2026

Copy link
Copy Markdown
Member

@pscheit , please rebase, because there are merge conflicts right now, that would block any further merge attempts.
Screenshot 2026-07-30 at 09 38 34

@pscheit

pscheit commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

hey @aik099 i would just close this. This was over a year without any interest, so it does not matter enough for this project i think.

This was just a suggestion and it's fine that this isnt a priority.

@aik099

aik099 commented Jul 30, 2026

Copy link
Copy Markdown
Member

That's life, I guess. Sometimes maintainers have time to maintain the project, sometimes they don't. People do have families and work that also requires their attention.

Always glad to see new people, like you, coming in and using open source projects.

It would be really cool if people using projects actually reported back, so it's visible how many people are interested in keeping the project alive. But I guess GitHub doesn't yet have an API for that 😄 .

@pscheit

pscheit commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

yeah i get it. It was not a comment directed to maintainers, more to generally everyone looking into this repo could have reviewed that and maybe pushed one thing or another forward.

I do have families and a lot of other responsibilities, so happy if someone takes this over, but if not I wouldnt hold a grudge.

I just don't want to pursue it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants