// composer.json
{
"require": {
"php": "^8.0.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.6", // v3.6.1
"composer/package-versions-deprecated": "^1.11", // 1.11.99.5
"doctrine/annotations": "^1.13", // 1.13.2
"doctrine/dbal": "^3.3", // 3.3.5
"doctrine/doctrine-bundle": "^2.0", // 2.6.2
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.0", // 2.11.2
"knplabs/knp-markdown-bundle": "^1.8", // 1.10.0
"knplabs/knp-time-bundle": "^1.18", // v1.18.0
"pagerfanta/doctrine-orm-adapter": "^3.6", // v3.6.1
"pagerfanta/twig": "^3.6", // v3.6.1
"sensio/framework-extra-bundle": "^6.0", // v6.2.6
"sentry/sentry-symfony": "^4.0", // 4.2.8
"stof/doctrine-extensions-bundle": "^1.5", // v1.7.0
"symfony/asset": "6.0.*", // v6.0.7
"symfony/console": "6.0.*", // v6.0.7
"symfony/dotenv": "6.0.*", // v6.0.5
"symfony/flex": "^2.1", // v2.1.7
"symfony/form": "6.0.*", // v6.0.7
"symfony/framework-bundle": "6.0.*", // v6.0.7
"symfony/mailer": "6.0.*", // v6.0.5
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/property-access": "6.0.*", // v6.0.7
"symfony/property-info": "6.0.*", // v6.0.7
"symfony/proxy-manager-bridge": "6.0.*", // v6.0.6
"symfony/routing": "6.0.*", // v6.0.5
"symfony/runtime": "6.0.*", // v6.0.7
"symfony/security-bundle": "6.0.*", // v6.0.5
"symfony/serializer": "6.0.*", // v6.0.7
"symfony/stopwatch": "6.0.*", // v6.0.5
"symfony/twig-bundle": "6.0.*", // v6.0.3
"symfony/ux-chartjs": "^2.0", // v2.1.0
"symfony/validator": "6.0.*", // v6.0.7
"symfony/webpack-encore-bundle": "^1.7", // v1.14.0
"symfony/yaml": "6.0.*", // v6.0.3
"symfonycasts/verify-email-bundle": "^1.7", // v1.10.0
"twig/extra-bundle": "^2.12|^3.0", // v3.3.8
"twig/string-extra": "^3.3", // v3.3.5
"twig/twig": "^2.12|^3.0" // v3.3.10
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.1
"phpunit/phpunit": "^9.5", // 9.5.20
"rector/rector": "^0.12.17", // 0.12.20
"symfony/debug-bundle": "6.0.*", // v6.0.3
"symfony/maker-bundle": "^1.15", // v1.38.0
"symfony/var-dumper": "6.0.*", // v6.0.6
"symfony/web-profiler-bundle": "6.0.*", // v6.0.6
"zenstruck/foundry": "^1.16" // v1.18.0
}
}
17 Comments
Hi, looking in rector to ajust my entities (+100 entities) like this video i found these
Should I use this or is there any other way?
Hey @sansxd ,
Yeah, Rector tool should be good for this, and your rules set looks good to me too. Give it a try, but don't forget to commit changes before running it. Also, you may want to apply code styles after Rector, e.g. run PHP CS Fixer: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer
Cheers!
This approach
is raising an error in PHPStan:
Do you know if there Is any clever way to ignore this rule in PHPSTAN w/o ignoring each line manually? How are you doing it?
There seems to be some conflicting philosophies (see: phpstan/phpstan issue 150) on this approach, but no solution or possibility to customize had been proposed.
Update:
I added this now into
phpstan.neon:Hi @Tim-K,
Good question, I guess you are using
phpstan/phpstan-doctrineextension, if so then you can try disable this check withtry to add it to your
phpstan.neonProbably this check is not comfortable, but from phpstan perspective if your column is not nullable then you should use
''empty string. I can't say is it good practice or not, however in some cases it can save you from unexpected behaviour.Cheers!
Hi SymfonyCasts,
I am trying to figure out what is the best way to use attributes for a decimal datatype in the database.
If I do it with
`type: 'decimal'`I get a string back, while i want to get a float:Now there is talk about using php-decimal, but is that really necessary?
I've also tried it with type 'float', but as I understand it correctly, it is recommended to work with decimal if you want to do calculations.
Thank you in advance.
Hey Annemieke-B!
Excellent question! I might... suggest something totally different. There is a general "best practice" out there (I don't know if it's programming-wide or just in PHP, due to our types) to avoid decimals and floats with prices. Instead, use integers.
The idea is that you store your
costPricein whatever the lowest denomination is of the currency - in other words, you store it in "cents". If something costs $45.33, you would store the integer4533in the database. This avoids weird things like getting strings or rounding issue (actually, the reason that it's giving you a string is to try to avoid rounding issues - e.g. 45.33 becoming something weird like45.33000000000001or something crazy like that). To help when rendering, you can add another getter method likegetCostPriceFormatted()where you return$this->costPrice / 100or even add a$in front of that and return a string.Let me know if this helps - we've absolutely done this on our site :).
Cheers!
Cheers!
Thank you Ryan for the quick response.
I knew about the cents option, that works great. Using it when I can and had some discussions about that with fellow programmers in the past.
So, this was a bad example i send you...., sorry.
So what about data that has decimals, because of other kinds of units and needs to be imported via a cronjob/command? E.g. laboratory data, with all kinds of units i have no knowledge of.
I'd really like to know how you would handle this.
Thank you!
Annemieke
Hi @Annemieke!
Sorry for my very slow reply!
Hmm. I don't have a lot of first-hand experience with floating-point calculations in PHP. But I do know that the reason Doctrine returns a
stringwith adecimaltype is exactly because it doesn't trust php to keep the exact precision if it returns it as adouble. From their docs:And the
floatDoctrine type is not meant for exact precision. So,doubleseems correct to me from a Doctrine perspective... simply because it uses a string, so we don't have the precision problem with using an actual number type in PHP. Then, if you need to do more than just print that number (e.g. you need to do some calculations), I imagine that is whyphp-decimalexists.I hope this helps :).
Cheers!
Thank you Ryan! This helped.
When adding property types in entities PhpStorm has a wonderful little helper to do them all in one go (on a file by file basis). Are you not using this so we learn how to do them ourselves or is it just not wise to do it that?
Steve
And where exactly is this tool? I cannot find it to save my life. =S
Howdy!
If I have a class like:
I believe Steve is referring to the ability to right-click on a property (
$alpha) -> selectingShow Context Actions-> selecting the "arrow" next toAdd 'string' as the property's type-> selecting "Fix all 'Missing property's type declaration' problems in file.Enjoy!
This does do the same thing, I think I'm so used to using the keys and that is how I came upon the fix but now I know this route I may change... Adopt Adapt and Improve :)
Cheers Jesse
In an entity class PHPStorm under lines properties if there is no property type specified.
I place the cursor on the property in question then (I'm on a Mac) hold down the option key and press enter
A menu pops up and the first option is "add [INSERT TYPE] as the property type. You can select this to complete or press the right arrow to expand the menu. The second option in this menu allows you to "Fix all missing property type" within the class
I hope I've explained this correctly.
Steve
It seems like a time-saver, but it is ignoring the recommendation given in this video to use type Collection instead of ArrayCollection:

That makes sense to me.
Thanks Steve!
Hey Steve D.
Good observation. Using PHPStorm to autocomplete your code is very useful, I use it as much as I can so I can save time and focus on the important things. I think Ryan don't use it too much avoid confusion and show exactly what's he doing
Cheers!
"Houston: no signs of life"
Start the conversation!