Giter Site home page Giter Site logo

php-formatter's People

Contributors

desarrolla2 avatar hacfi avatar hkdobrev avatar jakzal avatar javiereguiluz avatar jumbojett avatar matt-usurp avatar mhor avatar mickaelandrieu avatar mmoreram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-formatter's Issues

Exclude directories?

Is it possible to add excluded or ignored directories? It would be great to be able to prevent it from trying to sort use statements in my vendor directory or something.

Project status

Hi,

What is the project status?

1 - It is abandoned?
2 - It has support for PHP 7.4?

Fatal Errors with latest update and PHP 7.0+

I am having issues when running this on my docker box with the latest changes.

I find it strange that this gets past the build, but does the build ever test through the Console\Application class? This might want to be something we look in too if not?

Fatal error: Uncaught TypeError: ini_set() expects parameter 2 to be string, boolean given in /src/PHPFormatter/Console/Application.php on line 35

TypeError: ini_set() expects parameter 2 to be string, boolean given in /src/PHPFormatter/Console/Application.php on line 35

Call Stack:
    0.0007     351696   1. {main}() /bin/php-formatter:0
    0.0180     863312   2. Mmoreram\PHPFormatter\Console\Application->__construct() /bin/php-formatter:25
    0.0180     863312   3. ini_set() /src/PHPFormatter/Console/Application.php:35

The culprit looks to be here as described in the above stack and in the documentation:
https://github.com/mmoreram/php-formatter/blob/v1.3.1/src/PHPFormatter/Console/Application.php#L34-L37

And looks like PHP documentation has been updated for PHP 7.0.
string ini_set(string $varname , string $newvalue)
http://php.net/manual/en/function.ini-set.php

$ php -v

PHP 7.0.12 (cli) (built: Nov  8 2016 23:49:58) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.5.0rc1, Copyright (c) 2002-2016, by Derick Rethans

Grouping use-statements sometimes leaves gaps

I have been noticing this issue often and have been meaning to attempt to fix it. I haven't had time and I keep forgetting so I am creating this issue as a kind of reminder. Also hoping that someone will know exactly why this is happening and be able to submit a fix faster than me.

It looks like when sorting use-statements in fairly complex groups and two groups consecutively are not being used there are some additional spaces added.

Example pulled from my test classes.

use Project\Core\AClass;
use Project\Core\BClass;
use Project\Core\CClass;



use PHPUnit_Framework_MockObject_MockObject as MockObject;

With the following configuration:

use-sort:
  group:
    - Project\Core
    - Project\Integration
    - [Symfony, Sensio, Doctrine]
    - _main
  group-type: each
  group-skip-empty: true
  sort-type: alph
  sort-direction: asc

Please note that group-skip-empty is enabled also.

Expecting output:

use Project\Core\AClass;
use Project\Core\BClass;
use Project\Core\CClass;

use PHPUnit_Framework_MockObject_MockObject as MockObject;

Use sorting tries fixing traits in rare case

The use:sort command appears to have a bug where a class that has no imports but uses a trait from the same namespace it will treat the trait usage as if it was a file level import. This is causing issues in our builds which will fail the code on bad smell.

The replication is pretty simple. Have one class and a trait in the same namespace, make the class use the trait without import (as you should). In the examples below I added a method also to demonstrate that it also messes with the formatting of methods.

The command:

vendor/bin/php-formatter formatter:use:sort src --ansi

File structure:

src/MyTrait.php
src/MyClass.php

The class:

<?php

namespace SomeNamespace;

class MyClass
{
    use MyTrait;

    public function something() 
    {
        return 1;
    }
}

Now run the command above on the src directory and the output will look something like this:

<?php

namespace SomeNamespace;

class MyClass
{

use MyTrait;

public function something() 
    {
        return 1;
    }
}

Now obviously the temporary fix for this is to import the trait. Unless you are using an auto code formatter in which it will remove the useless import and then you are back where you started. Have you come across this issue? Personally I have never written a trait in the same directory as something implementing it one of my co-workers has and now this problem falls on me.

Feature request: Additional sorting functions

I would like to suggest some new features for the sorter:

  • add an option to put the extended class + interfaces at the top (or top of the group)
  • create a special group name _annotations which groups annotations (is that possible with the current implementation/in general?)
  • allow to combine groups like:
use-sort:
    group:
        - Symfony
        - _main
        - App
        - ['Sensio\Bundle\FrameworkExtraBundle\Configuration', 'JMS\DiExtraBundle\Annotation']
    group-type: each
    sort-type: alph
    sort-direction: asc
  • and ideally allow additional sorting within a group (like Symfony HttpKernel before Symfony Form e.g.)

Wdyt @mmoreram ?

Sorting replaces \n by \r\n

When sorting use clauses in PHP files under a Windows system (I used Windows 7, with PHP 7 RC5), the sorting makes the file invalidate a PSR-2 rule, as the line endings appended are the default from Windows (\r\n), instead of the ones from UNIX (\n).

Please see the attached image to apreciate that the endings have only been replaced in use clauses.

sorting_r_n

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.