r/PHPhelp • u/sysLee • Dec 21 '22
Feedback about fresh open source project
Hey community!
I hope it is okay to ask this here. I am working on my first "serious" open source project in my free time which I want to tag with version 1.0 soon and share it "officially" with others: https://github.com/leepeuker/movary
I would love to hear other people opinions on what I could improve there, like is the README understandable or is the project structure okay? I am afraid I am maybe missing some things I cannot see or exprience myself. Any feedback appreciated :)
3
u/ardicli2000 Dec 22 '22
I am nowhere near to criticize you as a junior, but there is something I see that is missing are comments and docblocks :)
3
u/sysLee Dec 22 '22
Hey, thank you for your input! I did not use many comments or docblocks on purpose. Imo code should be self explanatory and understandable without the need for comments to explain what is happening. If you need to explain something via comment you probably should refactor that code (there are exceptions of course). Additionally I do not see a reason for docblocks as long as they provide no extra information to what is already defined in the code (e.g. a @return array does not help much, because you can set the return type via code but a @return string[] can provide more information than you can do via code).
2
Dec 21 '22
Looks great but install without docker would open up to wider audiences
2
u/sysLee Dec 22 '22 edited Dec 22 '22
Hey, thanks for the feedback! I was thinking about that, but for now I was not able to invest additional time to enable a straight forward install without docker (working on this project in my free time which is not much currently). I guess I should create a GitHub issue for this
1
u/eurosat7 Dec 22 '22
I had no problems running it bare metal. docker is not mandatory. More a nice feature. ;)
1
u/sysLee Dec 22 '22
I had no problems running it bare metal. docker is not mandatory. More a nice feature. ;)
I think at least the image caching does require extra steps on a bare metal setup, because the symbolic link to the storage directory is set to the path used in docker. And you would have to setup the job processing yourself, in docker supervisor is making sure the job queue is getting processed. These are of course all solvable issues, but I had no time yet to "officially" document all these things (and provide easier solutions).
2
u/eurosat7 Dec 21 '22 edited Dec 21 '22
Its massive and amazing.
Some things are different than I'm used to.
I am used to doctrine annotations and doctrine migrations. Have to learn a bit to understand this way...
Your Entities have no common class or interface. If you are going to write some more universal code typehinting will become tricky.
Your Repositories have the same limitation. And they contain code which should be moved away (pe user and auth stuff).
The way you use a "Domain" is not really helping imho.
But overall I like it. :)
Readonly entities... Wild. Feels like functional/stateless programming. Haven't seen that often in php.
2
u/sysLee Dec 22 '22
Hey, thank you very much for the feedback!
Your Entities have no common class or interface
I saw no use cases for a common class for the entities (yet). Each entity defines only its individual properties and getters, there is nothing shared between them.
Your Repositories have the same limitation. And they contain code which should be moved away
Yeah that is true, my repositories are a bit all over the place and should be cleaned up, you definitely have a point there
The way you use a "Domain" is not really helping imho
Yes I am not feeling good about that too. My thought process was that I want to put all logic directly related to the internal app domain in one namespace, so that I have e.g.
Movary\Domain\Foobarwhich contains at least the three main classesFoobarApi(access to the functionality of that (sub)domain),FoobarEntity(represent the domain object closely coupled to its database definition) andFoobarRepository(execute database queries). I am pretty interested in DDD and this is one of my "interpretations" of it.Readonly entities... Wild.
The idea is to have hard contracts for mostly everything (e.g. a Movie Entity must have an ID to be valid, so the Entity should not be instantiable without it) to always guarantee its integrity and immutability to e.g. prevent side effects caused by the same object having different states at different places (one object -> one identity). Another thing I took from DDD :D
2
u/eurosat7 Dec 22 '22 edited Dec 22 '22
I dug deeper... ;)
I like your Makefile. It explains a lot of stuff. You are as "excessive" as me. :)
The php code itself is nice over all. So whatever I will say now ... keep that in mind! ;)
Your Commands should use the AsCommand attribute. You do not set name and description like that anymore. symfony 6 and php 8.2 changed it.
Your twig files can still improve. p.e.: Your navigation menu links could be an include or a macro, so you do not have to write all that "if path matches echo active" all over the place. If you only have it in ONE place it will be easier if you want to use a real router component one day.
You also have too much logic in twig (director.html.twig, building that baseUrl) - and your twig for navigating in a result set should be moved into a macro or include, too. So you can reuse it and have only one place to change... should you ever decide to change the looks or functionality.
You are having a hard time building your forms. Symfony Forms can help you a lot. They have an awesome twig bundle for form generation and validation.
You lack asset management (like webpack or encore, with scss support), and you are hotlinking to an alien server (cdn.jsdelivr.net) - having some npm or yarn to get the resources locally should be the way to go. Don't sell your customers.
Most of your phpUnit tests are useless. Do you know the difference between TDD and BDD? Focus more on the big stuff and ignore the details.
If you are interested pm me and I can show you some examples of my world.
ps: Factory is a mess! holy
2
u/sysLee Dec 22 '22
Thanks for digging deeper!
Yeah the twig files and related stuff is a mess, I do not like working on frontend very much and I am often getting to lazy and sloppy when touching these parts.
The external cdns are a good example, I should already have replaced these but did not look into this part good enough, thanks for catching it!I would not call the tests useless, just not as useful as tests for the bigger stuff, I definitely agree there. I have mostly written these tests passively while doing something else, that is not really possible with testing the more complicated business logic where I have to be more concentrate. Planning to add these later...
Factory is a mess! holy
Yeah that is true :D
2
u/czbz Dec 28 '22
I agree that it's good to avoid creating any common classes or interfaces when not necessary. YAGNI and all that, along with preferring composition over inheritance. If different entities can't be used interchangeably they don't have any reason to share a type.
2
1
u/czbz Dec 28 '22
Looks like an impressive piece of work. Have you found it useful for yourself yet? Do you have any users who are interested in it for the purpose of tracking and rating movies, rather than for trying out the software?
A few points on the code:
Since your entities have readonly properties, you don't need getter functions. You could make the code a lot more concise by simply making the properties public and losing the getters. You can always refactor to introduce private properties getters later if you find you have a need for them. That would be BC break for the PHP API, but since you're making an application and not a library that doesn't matter.
PhpStorm shows me that a lot of the getters are unused - e.g. all the getters on CastEntity, MovieGenreEntity::getMovieId and MovieGenreEntity::getPosition. This makes me wonder whether those properties actually have a good reason to be there.
I like that you're using Value Objects.
Since you're targeting PHP 8.1, and your Gender has only four possible values you make it an enum instead of a class, which should make things slightly simpler and more self-explanatory. Same applies to a few other VO classes that have a small number of possible values, e.g. JobStatus, JobType, SortOrder
If you're happy to bring in another library, you could replace your Date VO class with the LocalDate class from the brick/datetime library. It does the same thing, just has three int fields inside instead of a string in Y-m-d format.
Similarly you could use a library for the HTTP and Url related value objects. I'm not sure if you implemented these yourself for the exercise, or because you didn't think any of the available libraries were suitable.
Personally I like to see more rich objects that combine data fields and logic in object-oriented style, but I know not everyone agrees. One possibility might be a VoteCount class. Would probably be another value object, and could have a format method to replace VoteCountFormatter::formatVoteCount. The constructor could also validate that the count is within the legal range.
You have several functions that are only typed as returning array - e.g. UserApi::fetchAll. That means that when you call it you have to remember of work out what the structure of that array is before you can use it, and static analysis can't check you're using it correctly. I would either add a docblock to specify the type of the array, or (my preference) use a class instead of an array.
Why not make \Movary\Domain\Movie\MovieApi::findById return the movie entity object, instead of an API? Yes, this would couple the movie entity class directly to the MovieController and to the movie twig file, but I don't think that's a bad alternative to the indirect coupling you have via the non-typechecked contents of the array that findById currently returns.
It looks like your various entity list classes are almost identical. Maybe you could get rid of them and have a single generic EntityList class that you use instead. It could have multiple named constructors, or take the entity class as a constructor parameter, so that static analysis can know which class of entity any instance of the list is holding.
I think the logic in updateUserRating is unecassary. You don't need to have PHP code to check if you have a rating in the database, check if it's different to the requested rating and then only update it if it's different. That's up to three DB queries. You can probably implement upsert logic in a single SQL query.
1
u/czbz Dec 28 '22
You have 'crossover' entities, to represent relations between two other entities - e.g. MovieGenreEntity. I think crossover tables are a pattern specific to relational databases, and it would probably make more sense to keep those in the DB layer. In PHP you don't need it. I think you can lose the MoveGenre Entity and it's associated Repo class etc. There shouldn't be a rule that each repository can only use one DB table. MovieGenreApi::findByMovieId` is returning a list of Genres, not a list of of MovieGenres, so you could either move it to the GenreAPI, or simply make the list of Genres be a property of Movie, that's loaded via a join every time you load a Movie from the database.
4
u/Plastonick Dec 21 '22
I just skimmed over it, but it ticks most of the boxes I can think of. Looks on the surface like decent modern PHP, with a static analysis safety net to boot!