-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
PHP Code Style #10
Comments
Hallo, hier mal meine Meinung dazu: ich persönlich bin auch froh, wenn ich den Code nur mal schnell vom Server hole und sofort programmieren kann - ohne mir gedanken zu machen, welche Zusatztools ich benötige. (schliesslich sitzt man nicht sehr oft am heimischen PC) |
Ok ich versuchs nochmal etwas anders zu erklären: |
I have made some first tests: https://github.com/ximex/admidio/tree/code-style-fix-travis |
Bei zusätzlicher Software bin ich ganz bei Stefan. Wenn dies allerdings auf Serverseite läuft, dann gehts wieder. Allerdings sollten wir auch hier nicht die Hürde zum Checkin zu hoch machen. Man könnte aber mal mit ein paar einfachen Regeln anfangen. |
Also so wie ich das will würde das alles nur auf Serverseite laufen und kein zusätzlicher Aufwand für die Entwickler sein. Travis CI gibt nur ein Bsp: |
ok, das klingt so ganz gut und würde der formalen Code Qualität in Admidio wahrscheinlich nützen. Vielleicht fängt man erst einmal mit ein paar Prüfungen an, damit sich alle daran gewöhnen können und würde dann nach und nach weitere Regeln hinzufügen. Würdest du @ximex das weiter verfolgen? Ich würde in nächster Zeit ganz gerne den Fokus auf den Release der 3.0 setzen und darin dann meine Zeit investieren :) |
Ja würd ich übernehmen. Muss mich da zwar selbst noch bissl einarbeiten aber den ersten POC hab ich ja schon. |
Some questions about the prefered code style: if ($x === true) {
echo 'test';
} if($x === true) {
echo 'test';
} if ($x === true)
{
echo 'test';
} if($x === true)
{
echo 'test';
} The last one is the style i found mostly in the code. Which do you prefer? |
Look at the if ($a > $b) {
echo "a is größer als b";
} elseif ($a == $b) {
echo "a ist gleich groß wie b";
} else {
echo "a ist kleiner als b";
} if ($a > $b) {
echo "a is größer als b";
} else if ($a == $b) {
echo "a ist gleich groß wie b";
} else {
echo "a ist kleiner als b";
} |
require_once('system/common.php'); or require_once 'system/common.php'; |
we should prefer the second one if possible. if ($a == $b) if ($a === $b) |
There are some different style coding standards you can look here:
Here you can find some rules: |
I think this is already defined: |
if($x == true) {
echo 'test';
} or if($x == true)
{
echo 'test';
} I dont know. The other two are no option. Until now we choose the second one. But the first one will reduce code. What do you think @sirnone ? The elseif it my prefered style and we use until now. |
I prefer the second one, but this is mostly because i use it in all my code. |
if($x == true) {
echo 'test';
} or if($x == true)
{
echo 'test';
} have the same size in bytes. the first one is only one line less. @Fasse why don't you want a space between the back to this: if ($a == $b) if ($a === $b) what about this? Everywhere i read you should use the second one if possible. (faster, stricter comparison) |
next thing i found: if($x == true and $y == false) or if($x == true && $y == false) Do we prefer |
http://cs.sensiolabs.org/#usage Done/No Error foundPSR-0
PSR-1
PSR-2
Symfony
Todo/Discussion/Not TestedPSR-2
Symfony
Contrib
|
at combining strings i found different code styles: $x = 'Stringstart'.'Stringend';
$x = 'Stringstart' . 'Stringend';
$x = 'Stringstart'.$y.'Stringend';
$x = 'Stringstart' .$y. 'Stringend';
$x = 'Stringstart' . $y . 'Stringend'; I prefer a space between every |
if ($a == $b) if ($a === $b) This two phrases have different meanings. We should not target one with a commit check. People can use the second one but must not. Until now we use '&&' and '||'. At last I prefer By the way @ximex you have now admin rights :) |
ok because i found also then i will change all string joining with spaces between every string, dot and variable if it is not your codestyle without any space i know that
|
CodeStyle Check is active now! looking forward to change the email notifications (today only me got notified) and to make the tests stricter over the time |
But Now wie should Do no changes to the Beta. Changes like === Could lead to new Problems . Sometimes i want 5 === '5' |
@ximex Is it possible to revert changes to ===. This could lead and has lead to problems. If you do a mass change to this than you don't know where it get to problems. Please have a look at the two bugs that causes from this mass changes. |
issue #69 comes from a little other code optimization. if Every change could lead the a new bug but this doesn't mean that the change is bad idea. i only have to fix the new bug ;-) |
ok, but then we must fix these bugs so that the master is usable :) |
Question to SQL Code Style: Example: alter table %PREFIX%_users add constraint %PREFIX%_FK_USR_USR_CHANGE foreign key (usr_usr_id_change)
references %PREFIX%_users (usr_id) on delete set null on update restrict; To: ALTER TABLE %PREFIX%_users ADD CONSTRAINT %PREFIX%_FK_USR_USR_CHANGE FOREIGN KEY (usr_usr_id_change)
REFERENCES %PREFIX%_users (usr_id) ON DELETE SET NULL ON UPDATE RESTRICT; |
In my opinion YES. This is more readable if you don't have syntax highlighting. |
i'm for upper case |
the most things would get fixed in v3.1 |
So we can Close this issue? If there are something new to discuss we can open a new issue for that Special Thing. |
Plesse leave this still open. I will close it if i'm happy with the status |
Ok |
here it is easy to see which fixer is activated: |
Here are all PSR Standards: http://www.php-fig.org/psr/
|
What do you like more? // only if $xyz is always a bool !!!
// Current Version
if ($xyz == true)
if ($xyz == false)
// Change to:
if ($xyz === true)
if ($xyz === false)
// OR (my preferred version)
if ($xyz)
if (!$xyz) |
no i'm happy with the code. i think i will find some more small things but the could get also changed after this issue is closed. for bigger changes i will open a specific issue |
Hier sind die bisherigen CodeStyle-Richtlinien zu finden:
http://admidio.org/dokuwiki/doku.php?id=de:entwickler:programmierrichtlinien
Hier hab ich etwas gefunden von weit verbreiteten PHP CodeStyle Standards:
https://rwetzlmayr.github.io/php-the-right-way/
http://www.php-fig.org/
Die 2 Dokumente sind interessant:
http://www.php-fig.org/psr/psr-1/
http://www.php-fig.org/psr/psr-2/
Ich würde mir auch anschauen wie das mit automatischem Testing (hier mal bezogen auf CodeStyle) mittels Travis-CI geht:
http://docs.travis-ci.com/user/languages/php/
The text was updated successfully, but these errors were encountered: