{"id":4318,"date":"2022-04-15T07:09:20","date_gmt":"2022-04-15T07:09:20","guid":{"rendered":"https:\/\/saadashraf.net\/blog\/?p=4318"},"modified":"2022-04-15T07:09:20","modified_gmt":"2022-04-15T07:09:20","slug":"importance-of-implementing-psr-standards-for-laravel","status":"publish","type":"post","link":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/","title":{"rendered":"Importance of Implementing PSR Standards for Laravel"},"content":{"rendered":"<p>Setting a coding standard is vital in team development. Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them. For instance, strategy names are to be written in different styles, like camelCase, snake_case, and so on. <a href=\"https:\/\/www.saadashraf.net\/\"><strong>Web Developer Dubai<\/strong><\/a> will elaborate in this blog about PSR standards for Laravel.<\/p>\n<h2>PSR-0 and PSR-4<\/h2>\n<p>PSR-0 and PSR-4 are the two standards concerning namespaces, class names, and file paths. Since October 2014, PSR-0 has been censured. PSR-4 is presently suggested as another option. https:\/\/www.php-fig.org\/psr\/psr-0\/Since PHP has an automated instrument, each class name with a namespace should make them compare files.<\/p>\n<h3>PSR-0<\/h3>\n<p>In PSR-0, the accompanying guidelines are defined for the correspondence between class names with a namespace and file paths:<\/p>\n<ul>\n<li>Replace namespaces with directory separator \/<\/li>\n<li>Replace _ in class names with directory separator \/<\/li>\n<li>Add .php to the end<\/li>\n<\/ul>\n<p>PSR-4 is a new standard that has replaced PSR-0. Major changes are:<\/p>\n<p>_ in class names don\u2019t have any special meaning<\/p>\n<p>Therefore, file paths corresponding to \\vendorname\\name_space\\Class_Name are<\/p>\n<p>PSR-0: \/project\/path\/name_space\/Class\/Name.php<\/p>\n<p>PSR-4: \/project\/path\/name_space\/Class_Name.php<\/p>\n<p>Why there are both PSR-0 and PSR-4<\/p>\n<p>Namespaces for PHP were carried out from PHP5. Namespaces don\u2019t exist in past PHP versions. When there were no namespaces, there was an issue where class names frequently conflicted.<\/p>\n<p><img loading=\"lazy\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-4320\" src=\"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2022\/04\/laravel-web-development-300x177.png\" alt=\"laravel web development\" width=\"300\" height=\"177\" srcset=\"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2022\/04\/laravel-web-development-300x177.png 300w, https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2022\/04\/laravel-web-development-768x453.png 768w, https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2022\/04\/laravel-web-development-585x345.png 585w, https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2022\/04\/laravel-web-development.png 869w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>Strategies<\/h3>\n<p>Like properties, you should have both public\/ensured\/private and dynamic\/last comes after them whenever utilized. Static is the last modifier. You should not put any spaces previously, then after the fact braces, and you should put a newline before curly braces. Likewise, you should not place any whitespaces before commas in arguments, and you should put one whitespace after them.<\/p>\n<p>If there are an excessive number of arguments, you can put a newline after ( and keep in touch with one contention for every line. For this situation, you can\u2019t compose various factors on one line. Likewise, you ought to compose ) and { on a similar line, isolated by whitespace.<\/p>\n<p>Be careful, else if and else if are not the complete same things. else if is one statement by itself, but else if on the other hand is interpreted as an if statement in the else of the first if.<\/p>\n<p>For switch statements, case statements must be indented once from a switch, and bodies for the cases must be indented once from the case. When not breaking after any kind of operation in case, you must write a comment.<\/p>\n<h3>PSR-2 Coding Style Guide<\/h3>\n<p>PSR-2 is a part of the extension of the PSR-1 coding standard. Here we have represented a demographic:<\/p>\n<ul>\n<li>You should adhere to PSR-1 coding standards<\/li>\n<li>4 spaces should be utilized for indents. Utilizing tabs isn\u2019t permitted<\/li>\n<li>There is no restriction to line length, yet it ought to be under 120 characters, and best if under 80<\/li>\n<li>You should put a newline before curly braces for classes and techniques<\/li>\n<li>Methods and properties should be defined with conceptual\/last first, followed with public\/ensured, and finally static.<\/li>\n<li>You should not put a newline before curly braces in restrictive proclamations<\/li>\n<li>You should not put any spaces previously ( and ) in contingent articulations<\/li>\n<\/ul>\n<p>CakePHP and Symfony, which will be clarified later on in this article, depending on this PSR-2 standard.<\/p>\n<h3>Conditional Statements<\/h3>\n<p>For conditional statements,<\/p>\n<p>-&gt; You must put one whitespace before (<\/p>\n<p>-&gt; You must not put any whitespaces after (<\/p>\n<p>-&gt; You must not put any whitespaces before )<\/p>\n<p>-&gt; You must put one whitespace after )<\/p>\n<p>Also, use else if rather than else if.<\/p>\n<p>Be careful, else if and else if are not the complete same things. else if is one statement by itself, but else if on the other hand is interpreted as an if statement in the else of the first if.<\/p>\n<p>Subsequent to setting up a coding standard, we\u2019re certain there are situations where your codes are checked by code audits and so on to guarantee they are being followed. Lamentably, having people check the codes normally sets aside time and exertion and results in disregarded missteps. An instrument called PHP_CodeSniffer, which consequently runs checks about coding standards, can assist with settling these issues.<\/p>\n<p><a href=\"https:\/\/www.saadashraf.net\/\"><strong>Contact<\/strong> Dubai Web Developer today<\/a> for more information.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting a coding standard is vital in team development. Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them. For instance, strategy names are to be written in different styles, like camelCase, snake_case, and so on. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4319,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[34],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Importance of Implementing PSR Standards for Laravel -<\/title>\n<meta name=\"description\" content=\"Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Importance of Implementing PSR Standards for Laravel -\" \/>\n<meta property=\"og:description\" content=\"Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/\" \/>\n<meta property=\"og:site_name\" content=\"Blogs\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-15T07:09:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2022\/04\/Implementing-PSR-standards-for-Laravel.png\" \/>\n\t<meta property=\"og:image:width\" content=\"610\" \/>\n\t<meta property=\"og:image:height\" content=\"330\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\/\/saadashraf.net\/blog\/#\/schema\/person\/07c8e06409a4c41e57cc283478049b72\"},\"headline\":\"Importance of Implementing PSR Standards for Laravel\",\"datePublished\":\"2022-04-15T07:09:20+00:00\",\"dateModified\":\"2022-04-15T07:09:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/\"},\"wordCount\":729,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/saadashraf.net\/blog\/#organization\"},\"articleSection\":[\"Web Design\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/\",\"url\":\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/\",\"name\":\"Importance of Implementing PSR Standards for Laravel -\",\"isPartOf\":{\"@id\":\"https:\/\/saadashraf.net\/blog\/#website\"},\"datePublished\":\"2022-04-15T07:09:20+00:00\",\"dateModified\":\"2022-04-15T07:09:20+00:00\",\"description\":\"Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them.\",\"breadcrumb\":{\"@id\":\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/saadashraf.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Importance of Implementing PSR Standards for Laravel\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/saadashraf.net\/blog\/#website\",\"url\":\"https:\/\/saadashraf.net\/blog\/\",\"name\":\"Blogs\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/saadashraf.net\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/saadashraf.net\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/saadashraf.net\/blog\/#organization\",\"name\":\"Saad Ashraf\",\"url\":\"https:\/\/saadashraf.net\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/saadashraf.net\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2023\/03\/Saad-Ashraf-Logo.jpeg\",\"contentUrl\":\"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2023\/03\/Saad-Ashraf-Logo.jpeg\",\"width\":350,\"height\":162,\"caption\":\"Saad Ashraf\"},\"image\":{\"@id\":\"https:\/\/saadashraf.net\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/saadashraf.net\/blog\/#\/schema\/person\/07c8e06409a4c41e57cc283478049b72\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/saadashraf.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1dd2838ca55a7e429f4853f74d0eb550?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1dd2838ca55a7e429f4853f74d0eb550?s=96&d=mm&r=g\",\"caption\":\"admin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Importance of Implementing PSR Standards for Laravel -","description":"Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/","og_locale":"en_US","og_type":"article","og_title":"Importance of Implementing PSR Standards for Laravel -","og_description":"Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them.","og_url":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/","og_site_name":"Blogs","article_published_time":"2022-04-15T07:09:20+00:00","og_image":[{"width":610,"height":330,"url":"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2022\/04\/Implementing-PSR-standards-for-Laravel.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#article","isPartOf":{"@id":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/"},"author":{"name":"admin","@id":"https:\/\/saadashraf.net\/blog\/#\/schema\/person\/07c8e06409a4c41e57cc283478049b72"},"headline":"Importance of Implementing PSR Standards for Laravel","datePublished":"2022-04-15T07:09:20+00:00","dateModified":"2022-04-15T07:09:20+00:00","mainEntityOfPage":{"@id":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/"},"wordCount":729,"commentCount":0,"publisher":{"@id":"https:\/\/saadashraf.net\/blog\/#organization"},"articleSection":["Web Design"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/","url":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/","name":"Importance of Implementing PSR Standards for Laravel -","isPartOf":{"@id":"https:\/\/saadashraf.net\/blog\/#website"},"datePublished":"2022-04-15T07:09:20+00:00","dateModified":"2022-04-15T07:09:20+00:00","description":"Conceding to one coding standard, aides keep your code slick and simple to peruse and additionally make it simple to see the distinction in your code while inspecting them.","breadcrumb":{"@id":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/saadashraf.net\/blog\/importance-of-implementing-psr-standards-for-laravel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/saadashraf.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Importance of Implementing PSR Standards for Laravel"}]},{"@type":"WebSite","@id":"https:\/\/saadashraf.net\/blog\/#website","url":"https:\/\/saadashraf.net\/blog\/","name":"Blogs","description":"","publisher":{"@id":"https:\/\/saadashraf.net\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/saadashraf.net\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/saadashraf.net\/blog\/#organization","name":"Saad Ashraf","url":"https:\/\/saadashraf.net\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/saadashraf.net\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2023\/03\/Saad-Ashraf-Logo.jpeg","contentUrl":"https:\/\/saadashraf.net\/blog\/wp-content\/uploads\/2023\/03\/Saad-Ashraf-Logo.jpeg","width":350,"height":162,"caption":"Saad Ashraf"},"image":{"@id":"https:\/\/saadashraf.net\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/saadashraf.net\/blog\/#\/schema\/person\/07c8e06409a4c41e57cc283478049b72","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/saadashraf.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1dd2838ca55a7e429f4853f74d0eb550?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1dd2838ca55a7e429f4853f74d0eb550?s=96&d=mm&r=g","caption":"admin"}}]}},"_links":{"self":[{"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/posts\/4318"}],"collection":[{"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/comments?post=4318"}],"version-history":[{"count":1,"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/posts\/4318\/revisions"}],"predecessor-version":[{"id":4321,"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/posts\/4318\/revisions\/4321"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/media\/4319"}],"wp:attachment":[{"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/media?parent=4318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/categories?post=4318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/saadashraf.net\/blog\/wp-json\/wp\/v2\/tags?post=4318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}