Giter VIP home page Giter VIP logo

coderefactor's Introduction

Code Refactor


  • Validation must be applied to any function that is passing data to other function, specially in case of database queries.

  • variable names should be camelCase(PSR-2)

  • There should be no keys validation inside Repository. All checking must be validated using Validator in Controller.

  • Method docs must contain what method does.

  • There should be no database interaction from Controller.

  • Single quotes '' must be used instead of double quotes ""

  • Bind interface of Repository via ServiceProvider. Don't use RepositoryClass directly. It provides more control over structure.

  • Try to omit variables that are not in use(free up memory).

  • I did some code refactoring via PSR-2 standards to these files.

  • use of proper return type instead of mixed in function docs. It gives more insights what one will get from the method.

  • Maintain a config file with defaults, load the config key and make changes to it. it will save a lot of else conditions. Example:

  if (isset($data['customer_phone_type'])) {
    $data['customer_phone_type'] = 'yes';
  } else {
    $data['customer_phone_type'] = 'no';
  }

instead of this, load config keys and use those.

   $data = config->get('app.defaultOptions');
    if (isset($data['customer_phone_type'])) {
      $data['customer_phone_type'] = 'yes';
    }

Default options for customer_phone_type can have no as a default. This will omit a lot of else conditions from a single file, and from entire system.

  • Instead of returning everything with response method, use simple return without response. Laravel will wrap it into response by itself. However, use response method if you want to send back specific Status Code and headers.

  • _app contains old code, while app contains refactored code.

coderefactor's People

Contributors

mubin-khalid avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.