<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: PHP Rio</title>
    <description>The latest articles on Forem by PHP Rio (@phprio).</description>
    <link>https://forem.com/phprio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F2161%2F6e8ee19b-64ab-461f-9517-0b9e26f93e0b.jpg</url>
      <title>Forem: PHP Rio</title>
      <link>https://forem.com/phprio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/phprio"/>
    <language>en</language>
    <item>
      <title>Princípios ou Ferramentas - O que estudar</title>
      <dc:creator>Vinicius Dias</dc:creator>
      <pubDate>Thu, 23 Apr 2020 20:44:23 +0000</pubDate>
      <link>https://forem.com/phprio/principios-ou-ferramentas-o-que-estudar-1364</link>
      <guid>https://forem.com/phprio/principios-ou-ferramentas-o-que-estudar-1364</guid>
      <description>&lt;h2&gt;
  
  
  O mundo de desenvolvimento
&lt;/h2&gt;

&lt;p&gt;Quando decidimos entrar para o mundo de desenvolvimento, sofremos um bombardeio de informações e novos termos.&lt;/p&gt;

&lt;p&gt;Linguagens, frameworks, bibliotecas, paradigmas, princípios, etc. Não é fácil saber que caminho seguir e o que estudar primeiro.&lt;/p&gt;

&lt;p&gt;Obviamente não existe alternativa certa ou errada, então nesse post eu vou somente expor minha opinião. Não tome o que for dito aqui como verdade, mas sim reflita e analise se faz sentido para você.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mercado de trabalho
&lt;/h2&gt;

&lt;p&gt;É inegável que para atuar no mercado de trabalho nós precisamos de muito mais conhecimento do que nos é passado inicialmente em qualquer livro, curso ou post de blog. Somente a experiência e vivência vai nos dar a bagagem necessária para resolver os problemas e gerar valor para os clientes.&lt;/p&gt;

&lt;p&gt;Mas isso não quer dizer que nós só devamos estudar o que o emprego atual nos pede. Pelo contrário. Se nós estudamos além do que nos é pedido, ou no caso do primeiro emprego, estudamos antes de algo nos ser cobrado, quando uma oportunidade ou problema surgir, as chances serão muito maiores de estarmos prontos.&lt;/p&gt;

&lt;p&gt;Além de solucionar os problemas ou aproveitar as oportunidades, estudar nos faz conhecer melhores formas de atingir estes objetos, nos dando vantagens competitivas sobre quem simplesmente "resolve o problema".&lt;/p&gt;

&lt;p&gt;Ok, até aqui só usei o termo "estudo", mas devemos estudar o que? Ferramentas específicas ou princípios genéricos que podem ser aplicados a várias ferramentas?&lt;/p&gt;

&lt;h2&gt;
  
  
  Linguagens, bibliotecas e frameworks
&lt;/h2&gt;

&lt;p&gt;Se você quer entrar para a área de desenvolvimento e acredita que seu trabalho vai ser escrever código, você está enganado(a). O nosso trabalho é solucionar problemas. Código é uma ferramenta, um meio para o fim. Linguagens de programação são apenas ferramentas para nós resolvermos determinados problemas. Frameworks e bibliotecas nada mais são do que ferramentas de "alto nível", que nós trazem alguma facilidades e alguns problemas genéricos já resolvidos.&lt;/p&gt;

&lt;p&gt;Ah, Vinicius, quer dizer que a escolha da linguagem de programação não é importante? Longe disso! A linguagem de programação é uma ferramenta muito importante para a solução do problema e existem linguagens diferentes para solucionar problemas diferentes. O ponto é: elas são ferramentas.&lt;/p&gt;

&lt;p&gt;Se nós tivermos isso em mente, acabamos deixando de lado aquele tipo de briga de "minha linguagem é melhor que a sua" ou "meu framework é melhor do que o seu". Discussões desse tipo são interessantes e até emocionantes (eu mesmo adoro falar mal de Laravel ;-p), mas nós não podemos nos cegar achando que realmente há uma ferramenta melhor do que outra e ponto.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Não existe bala de prata&lt;/strong&gt; (solução pra qualquer problema)!&lt;/p&gt;

&lt;p&gt;Assim como cada linguagem resolve um problema, cada framework tem um propósito, uma identidade. Você vai acabar se identificando mais com um ou outro, mas não faça com que isso seja o foco de todo o seu estudo e trabalho. Conhecer muito bem a linguagem e o framework que você utiliza para trabalhar é importante, mas é o primeiro passo?&lt;/p&gt;

&lt;h2&gt;
  
  
  Paradigmas
&lt;/h2&gt;

&lt;p&gt;Como eu citei no último parágrafo, "cada linguagem resolve um problema", e cada linguagem faz isso de um jeito. Existem diversos paradigmas de programação, dentre eles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Declarativos

&lt;ul&gt;
&lt;li&gt;Programação funcional&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Imperativos

&lt;ul&gt;
&lt;li&gt;Programação procedural&lt;/li&gt;
&lt;li&gt;Programação orientada a objetos&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Entender bem as vantagens e desvantagens de cada paradigma e as diferenças entre eles é crucial para aprender qualquer linguagem de programação. Diversas linguagens modernas são o que chamamos de "multi-paradigma", ou seja, nos permitem utilizar mais de um paradigma em nosso código, como procedural e Orientado a Objetos, funcional e Orientado a objetos, funcional e procedural, etc.&lt;/p&gt;

&lt;p&gt;Este post (em inglês) fala com bem mais de detalhes sobre os principais paradigmas de programação e alguns exemplos de linguagens:&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/vplentinax" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F214333%2F2c277664-7e87-4565-bc6b-549c046cc14c.png" alt="vplentinax"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/vplentinax/classification-of-computer-languages-ii-2201" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Classification of computer languages (II)&lt;/h2&gt;
      &lt;h3&gt;Valentiina VP ・ Apr 13 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#devlive&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#computerscience&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Princípios
&lt;/h2&gt;

&lt;p&gt;Cada paradigma de programação (e suas respectivas linguagens suportadas) sugerem diversos princípios para que seu código seja de fácil manutenção, testável, legível, etc.&lt;/p&gt;

&lt;p&gt;Princípios muito comuns da programação orientada a objetos (paradigma que estudo mais a fundo) são:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tell, don't ask;&lt;/li&gt;
&lt;li&gt;Least astonishment;&lt;/li&gt;
&lt;li&gt;*Fail fast;&lt;/li&gt;
&lt;li&gt;*Early return;&lt;/li&gt;
&lt;li&gt;SOLID (conjunto de princípios);&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;* Princípios também aplicáveis a outros paradigmas&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Estudar os princípios referentes ao paradigma que você escolher é fundamental para manter seu código saudável. Não aplicá-los pode dar a falsa impressão de que você está sendo mais produtivo(a), mas a longo prazo a verdade sempre surge e nós acabamos nos arrependendo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Padrões
&lt;/h2&gt;

&lt;p&gt;Tendo entendido o que são paradigmas e que cada um deles possui princípios, baseando-se nestes princípios surgem padrões. Os famosos &lt;em&gt;Padrões de Projeto&lt;/em&gt; são basicamente soluções padrões para problemas genéricos. São sugestões de como proceder em determinadas situações.&lt;/p&gt;

&lt;p&gt;Certos problemas são tão comuns de acontecer, que pessoas através dos anos já estudaram e discutiram muito sobre as melhores formas de resolvê-los.&lt;/p&gt;

&lt;p&gt;Alguns dos padrões mais famosos seguindos os princípios da programação orientada a objetos são:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Padrões da "turma dos 4" (&lt;em&gt;Gang of Four "GoF"&lt;/em&gt;)

&lt;ul&gt;
&lt;li&gt;24 padrões (super famosos) separados em 3 categorias&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Object calisthenics

&lt;ul&gt;
&lt;li&gt;9 regras para exercitar em seus códigos&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Sugeridos pelo "desenvolvimento guiado a domínio" (&lt;em&gt;DDD&lt;/em&gt;)

&lt;ul&gt;
&lt;li&gt;Conhecidos como blocos de construção do &lt;em&gt;DDD&lt;/em&gt; como &lt;em&gt;Entity&lt;/em&gt;, &lt;em&gt;Value Object&lt;/em&gt;, etc.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Como citado no início do capítulo, cada padrão visa resolver problemas bem comuns e genéricos, e devem ser aplicados quando fazem sentido. Os padrões exemplificados estão em níveis bem diferentes de sua aplicação e explicá-los individualmente é impossível através de um único post.&lt;/p&gt;

&lt;h2&gt;
  
  
  O que estudar primeiro?
&lt;/h2&gt;

&lt;p&gt;Como foi dito lá no início, esse post é para que eu expressar &lt;strong&gt;minha opinião&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Na minha visão, devemos estudar o básico dos paradigmas de programação, entendendo qual problema cada um resolve e em que casos são usados. Após entendê-los, normalmente nos aprofundamos em 1 deles, mas existe um porém:&lt;br&gt;
Antes de aprender Orientação a Objetos, é importante conhecermos o paradigma procedural, visto que o primeiro surgiu para resolver determinados problemas do último.&lt;/p&gt;

&lt;p&gt;Para estudar um dos paradigmas, obviamente precisamos de uma linguagem de programação, então este estudo acontece em paralelo: Conhecemos uma linguagem enquanto conhecemos um paradigma.&lt;/p&gt;

&lt;p&gt;Após dominar razoavelmente bem os conceitos da linguagem e do paradigma em questão, podemos começar a estudar os princípios sugeridos, entendendo suas propostas, quais problemas resolvem, porque surgiram, etc.&lt;/p&gt;

&lt;p&gt;Estes princípios, normalmente nos levam naturalmente para o estudo de alguns padrões. O estudo de padrões já é um estudo mais avançado, porém muito recompensante.&lt;/p&gt;

&lt;p&gt;Se você tem um bom conhecimento de um paradigma (e consequentemente, uma linguagem), alguns de seus princípios e padrões, pode ser o momento de aprender a utilizar ferramentas que auxiliem no processo.&lt;/p&gt;

&lt;p&gt;Frameworks e bibliotecas são ferramentas que facilitam a resolução de problemas &lt;strong&gt;que você deveria saber resolver sem elas&lt;/strong&gt;. Richard Feynman, ganhador do Nobel de física, escreveu uma vez: “What I cannot create I do not understand”. Traduzindo: "O que eu não consigo criar eu não entendo".&lt;/p&gt;

&lt;p&gt;Então antes de utilizar um framework, sabia resolver o problema sem ele. Antes de utilizar uma biblioteca mais específica, saiba resolver o problema sem ela. Isso faz com que você consiga resolver um problema nas ferramentas, caso aconteça.&lt;/p&gt;

</description>
      <category>oop</category>
      <category>functional</category>
      <category>learning</category>
      <category>programming</category>
    </item>
    <item>
      <title>Programação procedural orientada a classes - Parte 2</title>
      <dc:creator>Vinicius Dias</dc:creator>
      <pubDate>Thu, 16 Apr 2020 16:37:50 +0000</pubDate>
      <link>https://forem.com/phprio/programacao-procedural-orientada-a-classes-parte-2-ofg</link>
      <guid>https://forem.com/phprio/programacao-procedural-orientada-a-classes-parte-2-ofg</guid>
      <description>&lt;h2&gt;
  
  
  Design de código
&lt;/h2&gt;

&lt;p&gt;Uma vez eu ouvi uma frase mas não me lembro o autor: "Não existe código sem design. Existe código com design ruim". Inclusive adaptei esta frase para "arquitetura" na primeira parte desta publicação.&lt;/p&gt;

&lt;p&gt;Antes de falarmos sobre as péssimas decisões de design que tomamos, vamos falar sobre o que é design de código.&lt;/p&gt;

&lt;p&gt;Uma analogia interessante foi feita pelo &lt;a href="https://twitter.com/junior_grossi" rel="noopener noreferrer"&gt;Junior Grossi&lt;/a&gt; em um workshop maravilhoso de qualidade de código que fiz com ele. Foi mais ou menos assim (não com essas exatas palavras):&lt;/p&gt;

&lt;p&gt;"Podemos fazer uma analogia da arquitetura de software com a arquitetura de uma casa. Onde fica cada cômodo, como se encaixam juntos, etc. É uma visão de bem &lt;strong&gt;alto nível&lt;/strong&gt;. Já o design de código pode ser considerado análogo aos móveis de uma casa. É uma visão de mais &lt;strong&gt;baixo nível&lt;/strong&gt; sobre nossas decisões sobre o código".&lt;/p&gt;

&lt;p&gt;Então, basicamente (beem basicamente), arquitetura diz respeito a como você vai separar sua aplicação em camadas, por exemplo, onde cada camada pode ter sua responsabilidade bem definida. Já o design de código diz respeito a como você vai organizar suas classes e métodos em cada uma das camadas. Quais padrões você vai seguir, como cada classe vai se comportar sozinha ou em conjunto com suas respetivas dependências, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Escolhas corriqueiras
&lt;/h2&gt;

&lt;p&gt;Agora que já entendemos basicamente o que é Design de Código, vamos falar sobre escolhas que fazemos frequentemente e que talvez não sejam as mais interessantes sob a ótica da programação orientada a objetos, ou melhor, sob a ótica do design orientado a objetos.&lt;/p&gt;

&lt;p&gt;Como já foi discutido no post anterior, é muito comum termos um modelo anêmico: Classes que apenas possuem &lt;code&gt;getters&lt;/code&gt; e &lt;code&gt;setters&lt;/code&gt;, ou seja, meros sacos de dados. Para quem já estudou C sabe que no fundo isso não é uma classe, mas sim uma &lt;code&gt;struct&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;O fato de termos modelos anêmicos onde classes que deveriam ser do nosso domínio na verdade acabam sem nenhuma regra de negócio, geralmente faz com que nós transfiramos essas regras para lugares "errados" (entre aspas porque quem sou eu pra dizer o que é certo ou errado?).&lt;/p&gt;

&lt;p&gt;Que lugares errados seriam esses?&lt;/p&gt;

&lt;h2&gt;
  
  
  Helpers ou Utils
&lt;/h2&gt;

&lt;p&gt;Quem nunca viu uma classe chamada &lt;code&gt;StringHelper&lt;/code&gt; ou &lt;code&gt;DateUtils&lt;/code&gt;? São classes que claramente estão perdidas em nosso sistema. O que seria, no mundo real, um(a) &lt;code&gt;StringHelper&lt;/code&gt;? Se não existe no mundo real, tem certeza que deveria existir no código?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Frc9OMWr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2Frc9OMWr.jpg" alt="Reflitão"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Esse tipo de classe é uma herança clara da programação procedural em nosso código onde estamos separando o comportamento dos seus dados, quando a orientação a objetos tem todas as ferramentas necessárias para nós os juntarmos.&lt;/p&gt;

&lt;h3&gt;
  
  
  Possível solução
&lt;/h3&gt;

&lt;p&gt;Se você possui uma classe &lt;code&gt;StringHelper&lt;/code&gt;, talvez ela esteja fazendo validações bem genéricas. Nesse caso, nada mais justo do que transformá-la em uma classe bem genérica, como &lt;code&gt;String&lt;/code&gt;. Nessa classe você pode ter comportamentos e verificações pertinentes a uma string em seu código.&lt;/p&gt;

&lt;p&gt;Mas na maioria das vezes as verificações nesse tipo de classe são específicas de regras de negócio. Ex.: Garantir que nome possua pelo menos 10 letras.&lt;/p&gt;

&lt;p&gt;Se é uma regra de negócio, deveria estar na classe de negócio. Talvez na classe &lt;code&gt;Pessoa&lt;/code&gt;. Talvez numa classe mais específica, como &lt;code&gt;Nome&lt;/code&gt;. Depende do seu sistema.&lt;/p&gt;

&lt;h2&gt;
  
  
  Services inúteis
&lt;/h2&gt;

&lt;p&gt;O livro do Eric Evans sobre DDD é certamente uma obra que revolucionou o mundo do desenvolvimento. Eu particularmente ainda não o li, mas li obras inspiradas por este livro, então sei que: Neste livro foram definidos alguns conceitos sobre classes chamadas de &lt;code&gt;Services&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Uma das possíveis "categorias" desse tipo de classe é &lt;code&gt;Application Service&lt;/code&gt;. Este tipo de classe tem como propósito receber informações de fora do domínio do sistema (da web, linha de comando, etc) e orquestrar as chamadas a regras de domínio.&lt;/p&gt;

&lt;p&gt;Um exemplo clássico:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AddUser&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;UserRepository&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;PasswordHasher&lt;/span&gt; &lt;span class="nv"&gt;$hasher&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__cosntruct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;UserRepository&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;PasswordHasher&lt;/span&gt; &lt;span class="nv"&gt;$hasher&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;hasher&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$hasher&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;AddUserDto&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$hashedPassword&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;hasher&lt;/span&gt;
            &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;password&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="nv"&gt;$user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$dados&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;email&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$hashedPassword&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Há pontos de melhoria nesse código (sempre há), mas basicamente: Ele recebe os dados de algum mecanismo de entrega através de um DTO (objeto de transferência de dados, que serve basicamente para transferir dados entre camadas no sistema), e passa para o domínio que sabe cifrar a senha, armazenar o usuário no repositório, etc.&lt;/p&gt;
&lt;h3&gt;
  
  
  Problema comum
&lt;/h3&gt;

&lt;p&gt;Essa definição de &lt;code&gt;Application Service&lt;/code&gt; em algum momento foi tomada por alguém como "Classe obrigatória para adicionar &lt;em&gt;indireção&lt;/em&gt; desnecessária no sistema".&lt;/p&gt;

&lt;p&gt;Na prática é muito comum vermos código onde um Controller chama um método de uma classe com &lt;code&gt;Service&lt;/code&gt; no nome, e esse método não faz nada além de chamar um método de outra classe. Essa chamada extra de um método é conhecida como indireção, de forma resumida.&lt;/p&gt;

&lt;p&gt;Algo parecido com isso:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;UserRepository&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;UserRepository&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$repository&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// todos os outros métodos públicos que também existem em UserRepository&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Agora me responda: O que ganhamos ao ter a classe &lt;code&gt;UserService&lt;/code&gt;? Ganhamos apenas mais indireções em nosso sistema. Mais um lugar que nossa IDE vai nos fazer passar até chegar no código que de fato executa algo.&lt;/p&gt;

&lt;p&gt;Além de parecerem ser classes conhecidas como &lt;em&gt;God classes&lt;/em&gt;, já que aparentam fazer tudo no sistema, são inúteis na prática.&lt;/p&gt;

&lt;p&gt;Esse é mais um exemplo de programação procedural sendo aplicada, onde temos apenas funções sem nenhum significado pro negócio agrupadas em uma classe que simplesmente chama outras funções.&lt;/p&gt;

&lt;p&gt;Outra característica de programação procedural nesse caso é que muito comumente temos métodos não tão relacionados na mesma classe &lt;code&gt;Service&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;É comum um &lt;code&gt;UserService&lt;/code&gt; ter um método com uma chamada para salvar um usuário e outro método para enviar um e-mail para ele. Responsabilidades que deveriam estar em classes separadas.&lt;/p&gt;

&lt;p&gt;No canal &lt;em&gt;Dev Eficiente&lt;/em&gt;, do Aberto Souza, tem um vídeo falando um pouco mais sobre o problema deste tipo de classe, mas sob uma outra ótica. Vale a pena conferir:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/szGb93_hXgI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;h2&gt;
  
  
  Camada Model do MVC
&lt;/h2&gt;

&lt;p&gt;Um ponto que tem levantado bastante discussão em comunidades que participo é: O que é a camada &lt;em&gt;Model&lt;/em&gt; no MVC?&lt;/p&gt;

&lt;p&gt;Discutir sobre MVC é assunto pra outro post, mas o que tenho visto como consenso é: Camada que faz a persistência dos dados.&lt;/p&gt;

&lt;p&gt;E a regra de negócio? Uma galera tem colocado nos &lt;em&gt;Controllers&lt;/em&gt;. E aí? Se essa lógica precisar ser reaproveitada, como fazemos? Como chamamos um &lt;em&gt;Controller&lt;/em&gt; dentro de outro? Complicado, né?&lt;/p&gt;

&lt;p&gt;Em nossos &lt;em&gt;Controllers&lt;/em&gt; é muito comum ver aquele código super famoso da programação procedural cheio de IFs e verificações em tipos primitivos, sem nenhum significado para o negócio.&lt;/p&gt;
&lt;h3&gt;
  
  
  Padrões arquiteturais
&lt;/h3&gt;

&lt;p&gt;Para "resolver" esse problema, diversos padrões arquiteturais existem, e eu falei um pouquinho (bem pouquinho) sobre arquitetura nesse meu outro post: &lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/phprio" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__org__pic"&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F2161%2F6e8ee19b-64ab-461f-9517-0b9e26f93e0b.jpg" alt="PHP Rio"&gt;
      &lt;div class="ltag__link__user__pic"&gt;
        &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F364363%2F662e513c-cd0f-4c7b-98d1-bd52d9a7550f.jpeg" alt=""&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/phprio/o-que-e-arquitetura-17ob" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;O que é arquitetura&lt;/h2&gt;
      &lt;h3&gt;Vinicius Dias for PHP Rio ・ Apr 10 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#php&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#architecture&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Por mais que a gente estude muito sobre ferramentas, frameworks, hypes e modinhas, os princípios da programação orientada a objetos mudam muito pouco e merecem MUITA atenção.&lt;/p&gt;

&lt;p&gt;Estude conceitos, princípios, padrões... Tudo isso vai poder ser aplicado naquele framework que foi lançado semana passada e você está doido pra usar pra fazer um CRUD. Acredite.&lt;/p&gt;

&lt;p&gt;Infelizmente eu ainda vejo muito código utilizando estas "técnicas" procedurais utilizando classes, e pessoas acreditando que isso é desenvolver utilizando a programação orientada a objetos.&lt;/p&gt;

&lt;p&gt;Você costuma ver código assim no seu dia a dia? Compartilha aqui nos comentários algum caso que você tenha visto recentemente.&lt;/p&gt;

</description>
      <category>php</category>
      <category>oop</category>
      <category>codequality</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Programação procedural orientada a classes</title>
      <dc:creator>Vinicius Dias</dc:creator>
      <pubDate>Mon, 13 Apr 2020 12:34:06 +0000</pubDate>
      <link>https://forem.com/phprio/programacao-procedural-orientada-a-classes-3i11</link>
      <guid>https://forem.com/phprio/programacao-procedural-orientada-a-classes-3i11</guid>
      <description>&lt;h2&gt;
  
  
  Farsa da programação Orientada a Objetos
&lt;/h2&gt;

&lt;p&gt;Acredito que todos concordamos que a programação Orientada a Objetos torna nosso código mais legível e permite arquiteturas mais interessantes do que a programação procedural, além de permitir recursos interessantes de reutilização de código.&lt;/p&gt;

&lt;p&gt;Partindo desse pressuposto, também acredito que seja intenção de qualquer pessoa que trabalhe com desenvolvimento aprender mais e mais as técnicas e boas práticas deste paradigma de programação.&lt;/p&gt;

&lt;p&gt;O problema acontece quando a gente vem de um aprendizado de programação procedural e tenta aplicar as mesmas técnicas fazendo uso de classes e objetos.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exemplo clássico
&lt;/h2&gt;

&lt;p&gt;Há um exemplo muito clássico de um código que claramente, embora utilize classes e objetos, é procedural:&lt;/p&gt;

&lt;h3&gt;
  
  
  Definição de uma classe
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$primeiroNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$ultimoNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nc"&gt;DateTimeInterface&lt;/span&gt; &lt;span class="nv"&gt;$dataNascimento&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;setPrimeiroNome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$primeiroNome&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;primeiroNome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$primeiroNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getPrimeiroNome&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;primeiroNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;setUltimoNome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$ultimoNome&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;ultimoNome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$ultimoNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getUltimoNome&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;ultimoNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;setDataNascimento&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nc"&gt;DateTimeInterface&lt;/span&gt; &lt;span class="nv"&gt;$dataNascimento&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;dataNascimento&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$dataNascimento&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getDataNascimento&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nc"&gt;DateTimeInterface&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;dataNascimento&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Utilização dela
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$pessoa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setPrimeiroNome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Vinicius'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setUltimoNome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Dias'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setDataNascimento&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nf"&gt;DateTimeImmutable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'1997-10-15'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// aceito presentes&lt;/span&gt;

&lt;span class="nv"&gt;$idade&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getDataNascimento&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nf"&gt;DateImmutable&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getPrimeiroNome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getUltimoNome&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; tem &lt;/span&gt;&lt;span class="nv"&gt;$idade&lt;/span&gt;&lt;span class="s2"&gt; anos"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Problema
&lt;/h3&gt;

&lt;p&gt;Olhando esse simples exemplo:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Você nota algum problema?&lt;/li&gt;
&lt;li&gt;Identifica semelhança com algum pedaço de código que você tenha escrito recentemente?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Depois de você refletir um pouco, vamos continuar.&lt;/p&gt;

&lt;p&gt;O código exemplificado utiliza uma classe &lt;code&gt;Pessoa&lt;/code&gt; e a partir desta classe, cria um objeto. Logo, está utilizando do paradigma de programação orientada a objetos, certo? Errado!&lt;/p&gt;

&lt;p&gt;Esse exemplo é claramente um código procedural que usa uma classe. Nada além disso.&lt;/p&gt;

&lt;h2&gt;
  
  
  Proposta
&lt;/h2&gt;

&lt;p&gt;Se você possui uma classe, os objetos gerados através dela devem ter seus comportamentos descritos (através de métodos) e não apenas fornecer os dados para realizar essas ações.&lt;/p&gt;

&lt;p&gt;O código anterior poderia ser escrito da seguinte forma para usar o paradigma Orientado a Objetos:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$primeiroNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$ultimoNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nc"&gt;DateTimeInterface&lt;/span&gt; &lt;span class="nv"&gt;$dataNascimento&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$primeiroNome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$segundoNome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nc"&gt;DateTimeInterface&lt;/span&gt; &lt;span class="nv"&gt;$dataNascimento&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;primeiroNome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$primeiroNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;ultimoNome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$ultimoNome&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;dataNascimento&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$dataNascimento&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;nomeCompleto&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;primeiroNome&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;ultimoNome&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;idade&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$hoje&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DateTimeImmutable&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;dataNascimento&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$hoje&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;E assim poderíamos utilizar esta classe:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="nv"&gt;$pessoa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Pessoa&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Vinicius'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Dias'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nf"&gt;DateTimeImmutable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'1997-10-15'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;nomeCompleto&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; tem &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$pessoa&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;idade&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; anos."&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Motivação da mudança
&lt;/h3&gt;

&lt;p&gt;Com essa simples modificação nós não temos mais instâncias inválidas, já que agora toda &lt;code&gt;Pessoa&lt;/code&gt; tem seu primeiro e último nome e sua data de nascimento. Antes, primeiro nós estávamos criando uma &lt;code&gt;Pessoa&lt;/code&gt; em um estado inconsistente, sem seus dados, para depois defini-los.&lt;/p&gt;

&lt;p&gt;Além disso, agora qualquer método que receba uma &lt;code&gt;Pessoa&lt;/code&gt; por parâmetro não precisa saber se nesse objeto o nome completo está separado em primeiro e segundo nome ou não. Não precisa saber como o cálculo da idade é feito.&lt;/p&gt;

&lt;p&gt;Caso a forma de apresentar o nome precise ser modificado (de "Vinicius Dias" para "Dias, Vinicius", por exemplo), podemos ir direto no ponto correto: O método &lt;code&gt;nomeCompleto&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Embora seja um exemplo muito simples, ele mostra com clareza como normalmente escrevemos código acreditando estar utilizando a programação orientada a objetos.&lt;/p&gt;

&lt;p&gt;Caso você tenha algum outro exemplo desse tipo em mente, já tenha visto algum código procedural com classes assim, ou tenha alguma outra sugestão de melhoria pra esse exemplo, que tal compartilhar com a gente aqui nos comentários?&lt;/p&gt;

&lt;h2&gt;
  
  
  Princípios e padrões
&lt;/h2&gt;

&lt;p&gt;Para nos ajudar a utilizar de forma mais "correta" a orientação a objetos, existem diversos padrões e princípios. Uns mais simples como o &lt;a href="https://youtu.be/6mfX6863SAk"&gt;Tell, Don't ask&lt;/a&gt;, outros mais completos e complexos como os princípios SOLID.&lt;/p&gt;

&lt;p&gt;Todos os princípios merecem uma atenção especial, porém isso foge do escopo deste artigo, mas uma rápida busca te mostra uma imensidão de conteúdo a respeito.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Muito frequentemente nós utilizamos o paradigma procedural em nosso código e só pelo fato de termos classes definidas no código, achamos que estamos utilizando a Orientação a Objetos.&lt;/p&gt;

&lt;p&gt;Este paradigma é muito mais do que apenas definir classes, atributos e métodos, logo, precisa de muito mais estudo do que apenas a leitura da documentação da sua linguagem favorita para aprender a sintaxe.&lt;/p&gt;

</description>
      <category>php</category>
      <category>oop</category>
      <category>codequality</category>
      <category>architecture</category>
    </item>
    <item>
      <title>O que é arquitetura</title>
      <dc:creator>Vinicius Dias</dc:creator>
      <pubDate>Fri, 10 Apr 2020 18:45:05 +0000</pubDate>
      <link>https://forem.com/phprio/o-que-e-arquitetura-17ob</link>
      <guid>https://forem.com/phprio/o-que-e-arquitetura-17ob</guid>
      <description>&lt;h2&gt;
  
  
  Problema
&lt;/h2&gt;

&lt;p&gt;Imagine que no momento da escrita desse artigo (ano de 2020) você esteja criando um sistema para a empresa que te contratou como desenvolvedor(a). Nesse sistema você pode utilizar todas as novas tecnologias, pode decidir como vai organizar o código, enfim, o sonho de qualquer pessoa que trabalha na área.&lt;/p&gt;

&lt;p&gt;Como você trabalha com PHP, escolhe o framework que está "na boca do povo": Laravel. Começa o desenvolvimento e rapidamente entrega uma primeira versão do projeto. A equipe de negócios está feliz com toda a velocidade de entrega e a equipe técnica está feliz de utilizar um framework da moda.&lt;/p&gt;

&lt;p&gt;Os anos se passam. No futuro, você precisa dar manutenção em um sistema que usa uma versão mega desatualizada do framework já que eles decidiram trocar a ferramenta que fazia o acesso ao banco de dados, e toda a regra de negócios da aplicação está em "models" do Eloquent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mundo real
&lt;/h2&gt;

&lt;p&gt;Parece irreal, né!?&lt;/p&gt;

&lt;p&gt;"Ah, mas o Laravel não vai deixar de usar o Eloquent. Não faz sentido esse exemplo"&lt;/p&gt;

&lt;p&gt;Bom, hoje eu trabalho em uma empresa que tem um software funcionando desde o PHP 3.&lt;/p&gt;

&lt;p&gt;Em algum momento da vida desse software, acharam uma boa ideia atrelar as regras de negócio a um projeto conhecido como Pear DB. Esse projeto hoje não recebe atualizações (apenas correções de segurança), além de nos deixar "amarrados" a sua filosofia de código, que difere do que temos nos mundos atuais de PSRs, Composer, etc.&lt;/p&gt;

&lt;p&gt;Resultado: O sistema evolui. Novas funcionalidades são adicionadas todo dia. A equipe de negócios continua recebendo suas demandas, mas como a forma de desenvolver não evoluiu junto com o conhecimento e ferramentas atuais, o prazo já não é o mesmo.&lt;/p&gt;

&lt;p&gt;Além disso, novos integrantes da equipe sofrem para entender todo o espaguete que o código virou. Caos!&lt;/p&gt;

&lt;h2&gt;
  
  
  Como poderia ter sido?
&lt;/h2&gt;

&lt;p&gt;Se os arquitetos desse sistema pudessem voltar no tempo, o que fariam, você pode se perguntar. Minha ideia aqui é levantar algumas opções.&lt;/p&gt;

&lt;p&gt;Em termos de código, entidades poderiam ter sido criadas sem nenhum conhecimento da infraestrutura que cuida da persistência. Se é utilizado Pear DB, PDO, Doctrine, Eloquent, uma API, um arquivo com os dados, tanto faz. A lógica de negócios estaria intacta.&lt;/p&gt;

&lt;p&gt;E para salvar no banco? Classes especializadas nessa tarefa, também conhecidas como repositórios, poderiam ter sido utilizadas. Essas classes saberiam lidar com as entidades e fazerem a tradução necessária para o sistema de persistência (usando SQL, por exemplo).&lt;/p&gt;

&lt;p&gt;E se a ferramenta usada fosse descontinuada? Bom, simples: Poderíamos criar uma &lt;code&gt;interface&lt;/code&gt; que define o que um repositório deve saber fazer. Quando o Pear DB deixasse de receber suporte, nossa classe &lt;code&gt;PearDbQuestionRepository&lt;/code&gt; (repositório de perguntas) poderia ser fácilmente substituída por uma classe &lt;code&gt;PdoQuestionRepository&lt;/code&gt;, ou até mesmo &lt;code&gt;DoctrineQuestionRepository&lt;/code&gt;. Isso não faria diferença para as regras de negócio, que precisavam de qualquer implementação da interface &lt;code&gt;QuestionRepository&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  O que isso tem a ver com arquitetura?
&lt;/h2&gt;

&lt;p&gt;— Essa solução proposta é perfeita?&lt;br&gt;
— Longe disso! Tem suas vantagens e desvantagens&lt;/p&gt;

&lt;p&gt;Decisões de como organizar nosso código de forma que ele continue "utilizável" após determinado período é o propósito mais simples de uma arquitetura.&lt;/p&gt;

&lt;p&gt;Arquitetura, segundo nosso querido Google, é: "arte e técnica de organizar espaços e criar ambientes para abrigar os diversos tipos de atividades humanas, visando tb. a determinada intenção plástica."&lt;/p&gt;

&lt;p&gt;Se trazemos isso para o mundo do desenvolvimento temos uma definição semelhante à seguinte: "A arquitetura de software de um sistema consiste na definição dos componentes de software, suas propriedades externas, e seus relacionamentos com outros softwares."&lt;/p&gt;

&lt;p&gt;Você pode encontrar inúmeras definições para esse termo, mas em sua essência, arquitetura de software nos ajuda a definir como organizar nosso código, torná-lo mais compreensível, manutenível a longo prazo, e separar a responsabilidades de domínio (regras de negócio) da infraestrutura (banco de dados, log, envio de e-mails, etc).&lt;/p&gt;

&lt;h2&gt;
  
  
  Padrões arquiteturais
&lt;/h2&gt;

&lt;p&gt;O exemplo que eu dei é bem raso e cita apenas um pequeno problema que uma arquitetura bem feita visa resolver. Para resolver diversos outros problemas, padrões arquiteturais surgiram ao longo do tempo.&lt;/p&gt;

&lt;p&gt;Você muito provavelmente conhece pelo menos um (nem que seja de nome), e aqui cito nomes de padrões arquiteturais bem famosos:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MVC (o famoso Model-View-Controller)&lt;/li&gt;
&lt;li&gt;ADR (Action-Domain-Response, uma espécie de evolução do MVC para web)&lt;/li&gt;
&lt;li&gt;SOA (Arquitetura orientada a serviços)&lt;/li&gt;
&lt;li&gt;Clean Architecture (em português, Arquitetura Limpa)&lt;/li&gt;
&lt;li&gt;Hexagonal Architecture (em português, Arquitetura Hexagonal)&lt;/li&gt;
&lt;li&gt;Onion Architecture (em português, Arquitetura em Camadas (cebola))&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Citar especificidades de cada padrão e suas semelhanças / diferenças fogem do escopo desse post, mas é interessante conhecer e se adaptar com alguns nomes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Não existe sistema sem arquitetura, só sistema com arquitetura ruim. &lt;/p&gt;

&lt;p&gt;Mesmo que no desenvolvimento de um sistema você não siga nenhum padrão arquitetural, há decisões de arquitetura no código, e se mal feitas, essas decisões podem te assombrar por muito (MUITO) tempo.&lt;/p&gt;

</description>
      <category>php</category>
      <category>architecture</category>
    </item>
    <item>
      <title>The state of Laravel-based APIs - a personal research</title>
      <dc:creator>Igor Santos</dc:creator>
      <pubDate>Tue, 12 Jun 2018 08:02:33 +0000</pubDate>
      <link>https://forem.com/phprio/the-state-of-laravel-based-apis-4e3</link>
      <guid>https://forem.com/phprio/the-state-of-laravel-based-apis-4e3</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Friendly disclaimer:&lt;/strong&gt; this is a quick and dirty post that I'm putting together as I research API resources to build an API for a project I'm working on, so I'm sorry for being so direct and to the point, and also for the number of levels and bullet points :)&lt;br&gt;
It was written in the order of "here only for the sake of completeness" down to "probably what we're going to use".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  TL;DR
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;GraphQL should be the way to go only if your frontend sort of requires it. Needs a lot of boilerplate and manual sync between your Eloquent models and GraphQL-related code.&lt;/li&gt;
&lt;li&gt;JSON-API is the most respected standard that could face GraphQL, but on Laravel-land it renders you documentation-less. You'll probably have to write separate documentation on API Blueprint or something like that, and it might take you some time as well. You can also discover how to get Blueprint generated through a specific package (that bridges JSON-API with Dingo), but... good luck on that.&lt;/li&gt;
&lt;li&gt;Handwritten RESTful API... Do I need to comment on that? It's handwritten. Certainly not a good option for a medium or big API. &lt;code&gt;EOF&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Prologue: basic API requirements we had
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;should have built-in documentation, that's not dependent on the developer to manually write it (think PHPDocs that magically autocomplete in your IDE)&lt;/li&gt;
&lt;li&gt;it needs to be blazing fast, as it will be used on a speed-sensitive user interface

&lt;ul&gt;
&lt;li&gt;here the features of field-selection from GraphQL or JSON-API come to my mind&lt;/li&gt;
&lt;li&gt;obviously, a simple cache layer might also be helpful&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h1&gt;
  
  
  Research and comparisons
&lt;/h1&gt;

&lt;h2&gt;
  
  
  API type option 1: &lt;a href="https://graphql.org/learn/" rel="noopener noreferrer"&gt;GraphQL&lt;/a&gt;
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Short conclusion.&lt;/strong&gt; Doesn't seem trivial to be built, as there's a lot of boilerplate to be written that repeats information from Eloquent: GraphQL Types, Queries, and Mutations. That happens on both packages found, and neither of them helps by having a boilerplate-generator.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Helpful Packages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/Folkloreatelier/laravel-graphql" rel="noopener noreferrer"&gt;By Folkore Atelier&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/rebing/graphql-laravel" rel="noopener noreferrer"&gt;By Rebing&lt;/a&gt;, based on Folklore's&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  API type option 2: RESTful
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Subtype 1: &lt;a href="http://jsonapi.org/" rel="noopener noreferrer"&gt;JSON-API&lt;/a&gt;
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Conclusion: also not that trivial to work with, but seems simpler than GraphQL. However, documentation might be a weak point.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Helpful packages
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://github.com/nilportugues/laravel5-jsonapi" rel="noopener noreferrer"&gt;Nil's Laravel5-json-api&lt;/a&gt;
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Implements &lt;code&gt;include&lt;/code&gt;, &lt;code&gt;fields&lt;/code&gt;, &lt;code&gt;sort&lt;/code&gt;, &lt;code&gt;page&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Almost boilerplate-free with generic controllers

&lt;ul&gt;
&lt;li&gt;However, you still need to &lt;a href="https://github.com/nilportugues/laravel5-jsonapi#step-3-definition" rel="noopener noreferrer"&gt;configure Transformers&lt;/a&gt;, although they don't repeat much information from the Eloquent model&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;No support for documentation generation. At all.&lt;/li&gt;

&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://github.com/nilportugues/laravel5-jsonapi-dingo" rel="noopener noreferrer"&gt;Laravel5-json-api-dingo&lt;/a&gt;
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Good points
&lt;/h6&gt;

&lt;p&gt;Theoretically, brings together the best of both packages, including Dingo's features (Dingo is discussed later) such as Auth, Versioning, Rate limiting, Docs and Routes into laravel5-json-api (called L5JA from now on).&lt;/p&gt;

&lt;h6&gt;
  
  
  Bad points
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/nilportugues/laravel5-jsonapi-dingo/issues/8" rel="noopener noreferrer"&gt;it's not clear how documentation could be generated&lt;/a&gt;, as Dingo depends on annotations and L5JA is ideally based on a generic controller implementation. There might be other integration issues, as the examples do not clearly define how to bring both packages together, besides a basic routing sample.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/nilportugues/laravel5-jsonapi-dingo/issues/7" rel="noopener noreferrer"&gt;support also seems to be lacking behind&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  &lt;a href="http://laravel-json-api.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt;cloudcreativity's Laravel-json-api&lt;/a&gt;
&lt;/h5&gt;

&lt;p&gt;This one has very long documentation; while seems complete, it might take a while to read everything and implement (took me a while reviewing the docs to see what features were available). And there are at least two empty pages, with a simple "todo" note.&lt;/p&gt;

&lt;h6&gt;
  
  
  Good points
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;also sort of boilerplate-free with generic controllers, and basic code generation for the other things (Adapters, Schemas)&lt;/li&gt;
&lt;li&gt;Adapters and Schemas will still need some filling and manual sync with the Eloquent model, though&lt;/li&gt;
&lt;li&gt;Also sports first-class validation rules for the API (which might end up being duplicated on your code, just like Eloquent details....)&lt;/li&gt;
&lt;li&gt;seems to have a decent Auth infrastructure&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Bad points
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;no clear mention on the docs about the selection of fields, and missing docs for sorting and "sparse fieldsets" (if that what I called "selection of fields"?) (&lt;a href="https://github.com/cloudcreativity/laravel-json-api/issues/193" rel="noopener noreferrer"&gt;issue on the topic&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://laravel-json-api.readthedocs.io/en/latest/fetching/filtering/#using-filter-parameter" rel="noopener noreferrer"&gt;filtering must be hand-written&lt;/a&gt; as well, there's no automatic API to turn filter parameters into Eloquent queries (much like GraphQL queries are built... sad).&lt;/li&gt;
&lt;li&gt;also, no mention about documentation generation. There's an &lt;a href="https://github.com/cloudcreativity/laravel-json-api/issues/94" rel="noopener noreferrer"&gt;old issue&lt;/a&gt; that states Swagger can't work together with JSON-API, and the main developer doesn't have time to dedicate to that (we all know how open-source is born and dies, right? Free developer time during the lifecycle of a related project...)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Subtype 2: Plain "bring-your-own-standard" JSON API
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Conclusion: the easiest to be built in our case, as we might end up needing only a couple of read-only endpoints. Might need some boilerplate to allow for field selection or advanced querying capabilities, but generates Blueprint documentation files and might even generate HTML docs with other generators.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Helpful Packages
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://github.com/dingo/api/wiki" rel="noopener noreferrer"&gt;Dingo&lt;/a&gt;
&lt;/h5&gt;

&lt;h6&gt;
  
  
  Good points
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;complete feature-set: auth, rate limiting helpers, errors, routing, doc generator (through Blueprint files)&lt;/li&gt;
&lt;li&gt;Blueprint files can be used with a number of parsers to, then, generate HTML documentation or similar. Options and related resources are listed at the bottom of this post.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Bad points
&lt;/h6&gt;

&lt;p&gt;Well... you'll have to write all your controllers and actions by hand. And define all your filters, if any. And whatnot.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;a href="https://github.com/Luracast/Restler" rel="noopener noreferrer"&gt;Restler&lt;/a&gt;
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;This is actually unrelated to Laravel, but Eloquent can be easily made to work with it, so it's worth mentioning as a companion project to your main Laravel application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h6&gt;
  
  
  Good points
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;complete feature-set, including Swagger documentation based on PHP Doc blocks and method parameters (that are also used for automatic request validation)&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Bad points
&lt;/h6&gt;

&lt;p&gt;Got abandoned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;stopped on PHP 5.4 support, while could have a great usage of PHP 7 first-class types&lt;/li&gt;
&lt;li&gt;stopped on an old version of Swagger, missing some of its features - probably one of the reasons the package got abandoned, as Swagger is sometimes referred as a very complicated beast to deal with.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  Sample implementation
&lt;/h6&gt;

&lt;p&gt;Once upon a time, I started working on an &lt;a href="https://bitbucket.org/dal-glossary/server/src/master/" rel="noopener noreferrer"&gt;API Server&lt;/a&gt; build with an Eloquent extension (also sort of abandoned) and Restler. It included some base controllers that made CRUD actions only a couple of lines away.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other useful resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://apiary.io/" rel="noopener noreferrer"&gt;Apiary&lt;/a&gt; - complete toolset (needs clarification!) to define, document and work on APIs.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://apimatic.io/transformer" rel="noopener noreferrer"&gt;Apimatic's transformer&lt;/a&gt; - UI and API that can translate to/from almost any doc format. Could be integrated in the API generation pipeline.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/apiaryio/dredd" rel="noopener noreferrer"&gt;Dredd&lt;/a&gt; - parses Blueprint/Swagger docs and automatically runs tests to ensure the Backend complies with the defined documentation.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/pixelfusion/blueman" rel="noopener noreferrer"&gt;Blueman&lt;/a&gt; &lt;em&gt;[probably outdated]&lt;/em&gt; - Generates Postman collections based on Blueprint files&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/SMillerDev/phpdraft/" rel="noopener noreferrer"&gt;PHPDraft&lt;/a&gt; - basic HTML generator from Blueprint files&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/M165437/laravel-blueprint-docs" rel="noopener noreferrer"&gt;Laravel Blueprint docs&lt;/a&gt; - generates integrated documentation inside your Laravel project, using its routing, and Blade templates for further customization.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>api</category>
      <category>rest</category>
      <category>graphql</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Quick tip on Git diffs for PHP files</title>
      <dc:creator>Igor Santos</dc:creator>
      <pubDate>Thu, 15 Sep 2016 23:00:00 +0000</pubDate>
      <link>https://forem.com/phprio/quick-tip-on-git-diffs-for-php-files</link>
      <guid>https://forem.com/phprio/quick-tip-on-git-diffs-for-php-files</guid>
      <description>&lt;p&gt;Every time a PHP developer runs &lt;code&gt;git diff&lt;/code&gt; on the command line a kitten dies:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AyE143yhomWgCeEdzer6Gmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AyE143yhomWgCeEdzer6Gmw.png" title="Badly-hunked PHP diff" alt="Badly-hunked PHP diff" width="394" height="113"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Hell no! This piece of code is inside a method, not the class :(&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Those &lt;code&gt;@@&lt;/code&gt; snippets are called Hunk Headers - because every part of a diff is called a hunk, duh. Unfortunately, git is too stupid to figure out PHP files should be diff'd according to PHP syntax, so you need to give it a hand by using a &lt;a href="https://git-scm.com/docs/gitattributes#__code_diff_code" rel="noopener noreferrer"&gt;rule on git attributes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Unfortunately(2), git attributes are not that easy to configure user-wide as config options are (no &lt;code&gt;git global&lt;/code&gt; commands), thus here's the tip:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;create the folder if it doesn't exist: &lt;code&gt;~/.config/git&lt;/code&gt; (or whatever is in &lt;code&gt;$XDG_CONFIG_HOME&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;write in &lt;code&gt;~/.config/git/attributes&lt;/code&gt; this: &lt;code&gt;*.php diff=php&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Save and diff away&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This can also be configured per project by adding the same text inside a &lt;code&gt;.gitattributes&lt;/code&gt; file.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AL5EKHPXHoTbO4j6CY0sxBQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F1%2AL5EKHPXHoTbO4j6CY0sxBQ.png" title="Well-hunked PHP diff" alt="Well-hunked PHP diff" width="429" height="114"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;There you have it! A decent Hunk Title on PHP files&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's quite weird why Git doesn't understand out of the box that through the file extension, as there are pre-baked settings to understand several syntaxes (such as TeX, Fortran, HTML, etc). Go figure!&lt;/p&gt;




&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://stackoverflow.com/questions/28026767/where-should-i-place-my-global-gitattributes-file" rel="noopener noreferrer"&gt;http://stackoverflow.com/questions/28026767/where-should-i-place-my-global-gitattributes-file&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>php</category>
      <category>codereview</category>
    </item>
  </channel>
</rss>
