New answers tagged

0

$productListUser = $this->em->getRepository(ProductAdmin::class) ->findProductsUser(... Than public function findProductsUser(UserInterface $user, int $number) :?array { $listProductUser = $this->em->getRepository(ProductAdmin::class)->findBy(... seems to me that findProductsUser is method of ...


1

Your code is mostly all right, especially given it's your first code attempt. I would say there is only on critical flaw. A post or a category is not a database connection. Hence it should be never extended from it. It would be like if you extend a human from a car simply because a human is going to ride a car. A car is a service used by a human, that ...


4

You could exploit Laravel collections to achieve what you need. Most of your code is checking for the presence/absence of props on your arrays. Laravel internally exposes and uses the Illuminate\Support\Arr class that contains a lot of useful methods to work with arrays without the hassles of checking for key existance. It also allows you to use dot ...


1

The code you posted doesn't seem to be doing what it says. From the way it is called and from the method's name one could tell it is intended to check if the id exists or not. But it doesn't return any answer to this question. instead it inserts some info into a database, which is extremely confusing. Also this code does some strange things like echoing the ...


2

Function modelExist should check if model exists and return boolean. Your function does something completely different. It only needs that check for its job. public function modelExists(int $modelId): bool; To check existence of a row, you don't need all its columns. Select just 1 (literally) and check if you have received a row from the query or not. ...


0

You might want to decompose it into smaller pieces that will be easier to follow and eventually modify. You could also learn a bit about dependency injection. Creating new instances all around anytime you need them is not very good. Here is a very simple rewrite of your code and a lot of pieces are missing but I hope it gives some general guideline. It ...


1

The way you currently doing it would require all the websites to be written manually. A possible alternative would be to implement recursion (loops). The for loop: For loops are a good way of repeating a section of code/similar code a number of times. The number of times to repeat this code can be known explicitly, or you can determine it through a simple ...


-1

you can simply use the for loop for such things, $totalUrl = 16;// change this number as your requirement for($i=0;$<$totalUrl;$i++){ $url = $chemin.'include/aaa/url.'$i'.php?param='.$param.'&page='.$p; // and here your code -include this or do whatever you want }


4

Dont call private methods in constructor, put the code into the constructor directly (well unless you have reason to call the same piece of code from elsewhere too, not your case tho). Don't put your db credentials into the class's constants. This way you are unable to use the class to connect to any other database. Well you can change their values, but ...


0

in addition to what has already been said, I'd suggest not using clientExists at all. just have a UNIQUE constraint on clientName, siteName and let the database enforce this for you. the reason is that your current code is both doing more work than is needed (the check for existence) as well not enough (the gap between the existence check and inserting a ...


1

Naming class Rosa tells me nothing. The name should scream out that it is a dependency injection container. PSR There is a standard interface for DI containers. https://github.com/php-fig/container/blob/master/src/ContainerInterface.php You might want to have you container implement it. Exit vs. Exception Implementing the PSR interface would ...


3

Reinventing the wheel You didnt make any indication that you are doing this as excercise. In that case you should try something already written and tested. Like Slim framework (http://www.slimframework.com/docs/v3/objects/router.html) which looks very similar to the "Express way". Also check out PSR interfaces. In case this is just an excercise for you or ...


1

I am going to post my thoughts without using profanity or defame thousands of developers that I've never met. I hope this will not lessen the perceived value or correctness of this content. First things first, I think it is important to know all of the viable tools at your disposal with php. Yes, str_replace() and preg_replace() are the two widely used ...


2

Toward optimization and better functionality consider using short array syntax [] instead of old-fashioned array() do not designate redundant captured groups such as ([0-9]{2})...([0-9]{2}) if you only need the 1st captured group ([^`]*?) regex [0-9] has a concise equivalent for designating digits - \d All those preg_replace calls in the initial approach ...


4

Most of such advises are crystal clear bullshit, on so many levels. You need to understand that such recommendations are never a result of some quality research, but just a rephrase of some vague rumor. The internet is full of chimpanzees. This particular advise didn't make any sense even for PHP5. That said, a set of consequent function calls apparently ...


2

SQL injection should not be a problem, as long as you pass any user input to queries through placeholders, which you do. I have a few other remarks though Single Responsibility Principle In the first code snippet you do too much things. You decode request json, you talk to db. you handle the logic, you maintain response structure. It would be wise to ...


2

Ad 1) it Is ok to pass id in the Array data of you want to change the id. If you were asking if you can omit the id argument. Then yes but you Will never be able to change id And honestly it becomes more verbose to use. And honestly it Is quite premature to expect this on this generic level. Ad 2) if "wrong" means empty id or database unreachable and ...


0

In a sutuation when a block of code is present in both branches of an if statement, you can move this common part out of this statement. for example, if (some condition) { $a = $x; $b = $y; $a = $z; } else { $a = $x; $b = $y; $a = null; } it can be rewritten to $a = $x; $b = $y; if (some condition) { $a = $z; } else { $a = ...


Top 50 recent answers are included