Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7548919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:49:09+00:00 2026-05-30T09:49:09+00:00

I’m working on a project(PHP) and on every commit there are some breaks on

  • 0

I’m working on a project(PHP) and on every commit there are some breaks on code convention. I’m using git for version control. Is there a way for automated code formatting so that all the code stays clean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:49:11+00:00Added an answer on May 30, 2026 at 9:49 am

    There are two parts to the question: automatically formatting the code, and detecting when it doesn’t conform to your coding standards.

    Automatically formatting the code is not really something you want to put inbetween you and your repo directly. Modifying files, or attempting to modify files, in a pre-commit hook is likely to make a mess. As such it doesn’t matter what vcs you are using.

    Using a tool to format the code via your editor or as a process you run (manually, or semi-automated) as part of your development workflow would be appropriate. For example, vim has the = function to auto-indent code, and as mentioned by others Pear’s beautifier is one possibility to do this.

    Detecting code standard devitions requires a cli tool that tells you when a file does not conform to coding standards – the obvious choice is PHP Code Sniffer (phpcs) – though it could simply be the same tool you use to beautify your code manually (if you use one) and checking that it doesn’t change the file contents.

    You may need to write your own standard to use with phpcs if none of the existing standards match your style.

    You can use a pre-commit hook to trigger a check on the code right before you commit it – If there are code errors found, you’ll be notified about them and the commit aborted. You can bypass your pre-commit hooks using git commit --no-verify

    You may find this repo useful: https://github.com/AD7six/git-hooks

    Example:

    $ more foo.php 
    <?php
        function bar() {
        }
    $ git add foo.php
    $ git commit -v
    running php/lint.php ...    OK
    running php/phpcs.php ...   FAIL
    phpcs -n -s --extensions=php,ctp --encoding=UTF-8 --standard=Cake '/tmp/cakephp-git-hooks'
    
    FILE: foo.php
    ---------------------------------------
    FOUND 3 ERROR(S) AFFECTING 2 LINE(S)
    ---------------------------------------
     2 | ERROR | Space indented: Tabs for indents, spaces for alignment (Cake.WhiteSpace.ForceTabIndent)
     2 | ERROR | Line indented incorrectly; expected 0 spaces, found 4 (Cake.WhiteSpace.ScopeIndent.Incorrect)
     3 | ERROR | Space indented: Tabs for indents, spaces for alignment (Cake.WhiteSpace.ForceTabIndent)
    ---------------------------------------
    
    Time: 0 seconds, Memory: 3.75Mb
    
    $
    

    (commit aborted, code does not meet code standards)

    $ git commit -v --no-verify -m "dummy commit"
    running misc/happy-commits ...  OK
    [2.1 2c432f1] dummy commit
     1 files changed, 3 insertions(+), 0 deletions(-)
     create mode 100644 foo.php
    $
    

    (commit succeeded – even though code standards were not met)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.