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

#476 crud improvements #477

Merged
merged 27 commits into from
Aug 17, 2019
Merged

Conversation

sallaberry
Copy link
Contributor

#476

Trying to make generated code compatible with Magento type hint checks

@astorm astorm mentioned this pull request Aug 9, 2019
@astorm
Copy link
Owner

astorm commented Aug 9, 2019

@sallaberry FYI -- I just opened a branch/pr where I'm going to try and get phpcs to do it's thing in our CI/CD build: #479

Once I get that running, we can incorporate that over here and ensure whatever files you intend to have pass the phpcs sniffs pass before checking stuff in.

I'll update this PR when I've got #479 working

@sallaberry
Copy link
Contributor Author

Ok thank you.

Also after reading more in the already opened similar issues like #273 I realise some of the modifications I submitted might not be to your liking:
I added PHPDoc for all methods, class, interfaces, and "pretty print" _construct/_init params in multiline because of php-cs line > 120 characters... It produces a lot more "noise" but makes my IDE happier.

I agree with the noise problem, but that would be a nice feature to have maybe with an optional argument like --with-phpdocs for all commands ?

@astorm
Copy link
Owner

astorm commented Aug 10, 2019

@sallaberry Re:

Also after reading more in the already opened similar issues like #273 I realise some of the modifications I submitted might not be to your liking:

That may have been true then, but this is now.

I'm not doing active, on the ground, Magento work these days (I mean, if someone threw a big giant pile of money or incentive at me I would, but that's another story for another time). I maintain pestle for the benefit of the community, and because I enjoy the privilege of having an open source project that has active users, but not so many active users that it drives me crazy :)

At this point, when it comes to the sort of code pestle generates for Magento, I'd rather leave it to someone like yourself and others who are actively engaged in working with the platform.

Re: Next steps.

I just merged a PR that adds a phpcs lint check to travis using the magento/magento-coding-standard rules. It's my understanding these are the new unified rules Magento developers are trying to adhere to.

Could you

  1. Pull the new master into this PR
  2. Add pestle.phar magento2:generate:... calls to for-lint.sh for the commands whose output you're changing.
  3. Make sure whatever changes you're making apply to these standards keeps travis happy
  4. Let me know if all this sounds reasonable, or if you have additional suggestions for improvements.
  5. Let me know if you run into trouble making the new phpcs work.

Does that sound OK/reasonable?

@sallaberry
Copy link
Contributor Author

Sounds OK.

  1. I have more improvements in mind, but first I'll try to make theses work / pass the new integrated phpcs

@sallaberry
Copy link
Contributor Author

sallaberry commented Aug 10, 2019

Are we sure Travis is git cloning the right branch? Feels like phpcs reports warnings that I already fixed in the current branch.. Maybe this?

In .travis.yml :

# download latest pestle phar and install
curl -LO "$PULSESTORM_PESTLE_URL/pestle.phar"

Shouldn't it build pestle.phar from current branch instead of downloading from your site?

I'm sorry I'm not familiar with Travis that much...

@astorm
Copy link
Owner

astorm commented Aug 11, 2019

Shouldn't it build pestle.phar from current branch

You're right. I'd forgotten where that pestle.phar came from and assumed it was the current branch/version. Give me 10/15 minutes and I'll have a "pestle_dev" command available for use in travis.

@astorm
Copy link
Owner

astorm commented Aug 11, 2019

Going to need to adjust that 10 - 15 minutes to "later tonight or tomorrow", but I've got a dirty version working here: https://github.com/astorm/pestle/pull/480/files if you want to give it a try

This will build and install a pestle.phar from the current branch -- not that pestle_dev approach I started with.

@sallaberry
Copy link
Contributor Author

Ok thanks I'll have a look.

@astorm
Copy link
Owner

astorm commented Aug 11, 2019

OK, master should have now have a pestle.phar that's built off of the branch that's been PR'd

@astorm
Copy link
Owner

astorm commented Aug 13, 2019

@sallaberry How are you feeling about this? Ready for me to take a look and merge? Or are you still working on stuff?

@sallaberry
Copy link
Contributor Author

Yes I think it's ready if you take a look at what I've done so far. Please check I didn't break anything... I didn't modify the generated php too much so I think It's all good.

Copy link
Owner

@astorm astorm left a comment

Choose a reason for hiding this comment

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

@sallaberry Thanks again for taking this on. I think we're almost there. I just submitted a review with a few comments/questions. If you can answer those and bring the branch up to date with master I think we'll be all set to merge this.

@@ -11,4 +11,6 @@
mkdir -p app/code/Pulsestorm/Travis
printf "<?php\nnamespace Pulsestorm\\Travis;\n\nclass Foo\n{\n}\n" > app/code/Pulsestorm/Travis/Test.php

# pestle.phar magento2:generate:crud-model Pulsestorm_Travis Thing
## test generate:crud-model, rm InstallSchema backup file
pestle.phar magento2:generate:crud-model Pulsestorm_Travis Thing
Copy link
Owner

Choose a reason for hiding this comment

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

I'm looking at this line -- am I correct that this PR is only concerned with the formatting on the following files?

app/code/Pulsestorm/Travis/Model/Thing.php
app/code/Pulsestorm/Travis/Model/ThingRepository.php
app/code/Pulsestorm/Travis/Model/ResourceModel/Thing.php
app/code/Pulsestorm/Travis/Model/ResourceModel/Thing/Collection.php

Copy link
Contributor Author

Choose a reason for hiding this comment

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

9 files are generated, 8 if you remove the .bak file

app/code/Pulsestorm/Travis/Model/Thing.php
app/code/Pulsestorm/Travis/Model/ThingRepository.php
app/code/Pulsestorm/Travis/Model/ResourceModel/Thing.php
app/code/Pulsestorm/Travis/Model/ResourceModel/Thing/Collection.php

app/code/Pulsestorm/Travis/Api/ThingRepositoryInterface.php
app/code/Pulsestorm/Travis/Api/Data/ThingInterface.php
app/code/Pulsestorm/Travis/Setup/InstallSchema.php
app/code/Pulsestorm/Travis/Setup/InstallData.php

They all pass phpcs checks now.

In InstallData.php I disabled phpcs for the ->install() method (empty function)
I tried disabling just the specific rule ( // phpcs:disable Magento2.CodeAnalysis.EmptyBlock.DetectedFUNCTION ) it works locally but fails in Travis build.

# pestle.phar magento2:generate:crud-model Pulsestorm_Travis Thing
## test generate:crud-model, rm InstallSchema backup file
pestle.phar magento2:generate:crud-model Pulsestorm_Travis Thing
rm app/code/Pulsestorm/Travis/Setup/InstallSchema.php.*.bak.php
Copy link
Owner

Choose a reason for hiding this comment

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

+1 for getting rid of the backup files -- what do you think about making this a bit more generic. Something like ...

find app/code/Pulsestorm/Travis -type f -name '*.bak*' -exec rm '{}' \;

That'll get rid of any/all .bak files now and in the future.

@sallaberry
Copy link
Contributor Author

Sorry for the delay, I made the requested changes.

@astorm astorm added this to the Current Undated Sprint milestone Aug 17, 2019
@astorm
Copy link
Owner

astorm commented Aug 17, 2019

Great work @sallaberry! And re:

Sorry for the delay, I made the requested changes.

You're offering your free time to improve this software project -- so you get to decide how long you take :)

Merging the changes now. I've added this soon-to-be-closed-PR to the "current undated sprint" milestone, and it will go out in the next release of pestle -- which should be soonish (probably when I finish up the remaining documentation items for pestle/internals over on https://pestle.readthedocs.io)

Also, semi related, this work led me to open a new issue: #491 -- I think I'd like to get those backup files out of the module folder itself and put somewhere else.

@astorm astorm merged commit 5622bcf into astorm:master Aug 17, 2019
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.

2 participants