5 Maneiras de melhorar seu código PHP
-
Upload
augusto-das-neves -
Category
Technology
-
view
718 -
download
1
Transcript of 5 Maneiras de melhorar seu código PHP
![Page 1: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/1.jpg)
$maneirasDeMelhorarSeuCodigo
Aplicando 5S no seu código
AUGUSTO DAS NEVES@AUGUSTO_DAS
![Page 2: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/2.jpg)
2
Agenda
Origem
Conceitos
Considerações
![Page 3: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/3.jpg)
3
ORIGEM5S
![Page 4: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/4.jpg)
4
![Page 5: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/5.jpg)
5
$Limpeza = $Seiso = 清掃 PHPCSD PHPMD
PHPDEPEND
X
![Page 6: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/6.jpg)
6
QA TOOLS• PHP QA TOOLS - http://phpqatools.org/
• PHPUnit• PHP_Depend• PHP Dead Code Detector• PHP_CodeSniffer• PHP Mess DetectorEntre outros...
![Page 7: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/7.jpg)
7
$organizacao[] = $seiton = 整頓 Linha Guia
![Page 8: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/8.jpg)
8
Convenção de Código
• Zend Coding Standards - http://framework.zend.com/manual/1.12/en/coding-standard.html
• PEAR - http://pear.php.net/manual/en/standards.php
![Page 9: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/9.jpg)
9
<?php foreach($consulta as $valor): ?> <tr> <td><?php echo $valor->id; ?></td> <td><?php echo $valor->nome; ?></td> <td><?php echo $valor->email; ?></td> <tr> <?php endforeach; ?>
Servido?
![Page 10: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/10.jpg)
10
$organizacao[] =$namespacesCriado para resolver o problema de escopo entre bibliotecas.*Namespace pode conter definições de classes, constantes e funções, mas não código livre. (A partir da versão 5.3)
<?php namespace core\Controller\Hello;
class World { function __construct() { echo "Helloworld"; } } ?>
![Page 11: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/11.jpg)
11
Qual é a ideia?
Core
DB
URL
![Page 12: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/12.jpg)
12
Paradigma?
• Estude-os (objetos,aspectos,eventos)• Há projetos?
![Page 13: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/13.jpg)
13
• Gere sua documentação automaticamente• Gerencie suas tarefas através do seu código
$organizacao[] =$phpdocumentor
![Page 14: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/14.jpg)
14
![Page 15: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/15.jpg)
15
Exemplo
![Page 16: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/16.jpg)
16
Isso é justificável hoje?<?phpfunction require_path($path) { $root = scandir($path); $files = array(); foreach($root as $value) { if($value === '.' || $value === '..') {continue;} if(is_file("$path/$value")) { $pInfo = pathinfo($value); if ($pInfo['extension'] == "php") { require_once("$path/$value"); echo "$path/$value<br>"; } } else { require_path($path); } }}?>
![Page 17: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/17.jpg)
17
Como podemos modificar isso?
scandir($dir)
__autoload($classname)
use
![Page 18: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/18.jpg)
18
$utilidade= $seiri = 整理 O que é util?
Refatore
![Page 19: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/19.jpg)
19
Refatoração
• Maioria das técnicas associadas ao oop!Extrair Método (Extract Method)Mover Método (Move Method)Mover Atributo (Move Field')Extrair Classe (Extract Class)Encapsular Atributo (Encapsulate Field)Renomear Método (Rename Method)Subir Método (Pull Up Method)Subir Atributo (Pull Up Field)Descer Método (Push Down Method)Descer Atributo (Push Down Field)Extrair Sub-classe (Extract Subclass)Extrair Super-classe (Extract Superclass)
![Page 20: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/20.jpg)
20
清潔 , Seiketsu
Café?Coca-Cola
![Page 21: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/21.jpg)
21
躾 , Shitsuke
Disciplina
![Page 22: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/22.jpg)
22
Considerações Finais
DRY(Do not repeat yourself) – (Já Falamos)KISS(Keep it simple, stupid) – Menos é mais
Php.netGUIA
![Page 23: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/23.jpg)
23
Perguntas
![Page 24: 5 Maneiras de melhorar seu código PHP](https://reader038.fdocumentos.tips/reader038/viewer/2022110220/547cac5fb4af9f5d5b8b45e7/html5/thumbnails/24.jpg)
24
Obrigado