41
REFATORANDO CÓDIGOS PHP LEVI FERREIRA / @leviferreira PHP CONFERENCE BRASIL 2013

Refatorando Códigos PHP - PHP Conference 2013

Embed Size (px)

Citation preview

Page 1: Refatorando Códigos PHP - PHP Conference 2013

REFATORANDO

CÓDIGOS PHP

LEVI FERREIRA / @leviferreira PHP CONFERENCE BRASIL 2013

Page 2: Refatorando Códigos PHP - PHP Conference 2013

SOBRE O PALESTRANTE

- Desenvolvedor PHP há 4 anos

- Zend Certified Engineer PHP 5.3 desde jun/2013

- Apaixonado por música

- Amante da tecnologia

- Atualmente desenvolvedor na ClickBus venture da Rocket Internet!.

ESTAMOS CONTRATANDO!

Page 3: Refatorando Códigos PHP - PHP Conference 2013

MAS A FINAL

O QUE É

REFATORAÇÃO ?

Page 4: Refatorando Códigos PHP - PHP Conference 2013
Page 5: Refatorando Códigos PHP - PHP Conference 2013

“Refatoração consiste em uma reelaboração

de todo o projeto devido a alta quantidade de

erros e falta de aderência a requisitos do

cliente (que alias, estao aonde mesmo?)”

Desciclopedia

NÃO!! NÃO É ISSO…

Page 6: Refatorando Códigos PHP - PHP Conference 2013

“A refatoração é um processo de alteração de

código-fonte de um sistema de software de modo

que o comportamento observável não mude, mas

que sua estrutura interna seja aperfeiçoada. Em

essência, quando se usa esse processo, tende-se a

melhorar o código-fonte, mesmo após este já ter

sido escrito.” Martin Fowler

AGORA SIM!!!

Page 7: Refatorando Códigos PHP - PHP Conference 2013

POR QUE SE FAZ NECESSÁRIO

A REFATORAÇÃO ?

Page 8: Refatorando Códigos PHP - PHP Conference 2013

TODO SOFTWARE ESTÁ

Page 9: Refatorando Códigos PHP - PHP Conference 2013

MUITOS PROGRAMADORES PHP

NÃO SABEM

ORIENTAÇÃO A OBJETOS

NÃO SABEM

NÃO SABEM

NÃO SABEM

Page 10: Refatorando Códigos PHP - PHP Conference 2013

RACIOCÍNIO ESTÁTICO

Page 11: Refatorando Códigos PHP - PHP Conference 2013

LINGUAGEM NOVA, MAS

HÁBITOS ANTIGOS

Page 12: Refatorando Códigos PHP - PHP Conference 2013

MAS O QUE

A REFATORAÇÃO TRAZ DE

BOM ?

Page 13: Refatorando Códigos PHP - PHP Conference 2013

DIMINUI A COMPLEXIDADE DO CÓDIGO

Page 14: Refatorando Códigos PHP - PHP Conference 2013

MINIMIZA O RISCO DE FALHAS

Page 15: Refatorando Códigos PHP - PHP Conference 2013

ORGANIZAÇÃO

Page 16: Refatorando Códigos PHP - PHP Conference 2013

MODULARIZAÇÃO

Page 17: Refatorando Códigos PHP - PHP Conference 2013

FACILITAR

A MANUTENÇÃO

Page 18: Refatorando Códigos PHP - PHP Conference 2013

Por onde

começar?

par où

commen

cer ?

por dónde

empezar?

por onde

comezar?

wo ich anfangen?

Page 19: Refatorando Códigos PHP - PHP Conference 2013

COMECE PELAS CAMADAS MAIS

EXTERNAS DA APLICAÇÃO

Page 20: Refatorando Códigos PHP - PHP Conference 2013

TESTES

Page 21: Refatorando Códigos PHP - PHP Conference 2013

LIMPANDO COISAS QUE

CHEIRAM MAL

Page 22: Refatorando Códigos PHP - PHP Conference 2013

ELIMINE O CÓDIGO DUPLICADO

Page 23: Refatorando Códigos PHP - PHP Conference 2013

ELIMINE O CÓDIGO DUPLICADO

Page 24: Refatorando Códigos PHP - PHP Conference 2013
Page 25: Refatorando Códigos PHP - PHP Conference 2013
Page 26: Refatorando Códigos PHP - PHP Conference 2013

MANTENHA SEUS

METODOS E CLASSES PEQUENOS

Page 27: Refatorando Códigos PHP - PHP Conference 2013

DÊ NOMES CERTOS

AOS PARAMÊTROS, VARIÁVEIS

E MÉTODOS

Page 28: Refatorando Códigos PHP - PHP Conference 2013

SUBSTITUA

NÚMEROS

MÁGICOS

POR CONSTANTES

Page 29: Refatorando Códigos PHP - PHP Conference 2013
Page 30: Refatorando Códigos PHP - PHP Conference 2013

DIVIDA

RESPONSABILIDADES

Page 31: Refatorando Códigos PHP - PHP Conference 2013
Page 32: Refatorando Códigos PHP - PHP Conference 2013
Page 33: Refatorando Códigos PHP - PHP Conference 2013
Page 34: Refatorando Códigos PHP - PHP Conference 2013
Page 35: Refatorando Códigos PHP - PHP Conference 2013

SIMPLIFIQUE

AS CONDIÇÕES

Page 36: Refatorando Códigos PHP - PHP Conference 2013

NÃO TENHA MEDO DIGA PARA A CLASSE:

Page 37: Refatorando Códigos PHP - PHP Conference 2013

FAÇA OS OBJETOS SE

COMPORTAREM COMO COLEÇÕES

Page 38: Refatorando Códigos PHP - PHP Conference 2013

COMENTE SEU CÓDIGO! NÃO CUSTA NADISS

SENÃO SEU CODIGO PODE SER VISTO ASSIM:

Page 39: Refatorando Códigos PHP - PHP Conference 2013

FAÇA PAIR PROGRAMMING

Page 40: Refatorando Códigos PHP - PHP Conference 2013

AO FINAL, VOCÊ DEVE FICAR ASSIM

MAS COM CERTEZA TERÁ VALIDO A PENA

Page 41: Refatorando Códigos PHP - PHP Conference 2013

OBRIGADO!