Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP CS Fixer 2.0.x not working #15

Open
vysker opened this issue Dec 15, 2016 · 21 comments
Open

PHP CS Fixer 2.0.x not working #15

vysker opened this issue Dec 15, 2016 · 21 comments
Assignees
Labels

Comments

@vysker
Copy link
Owner

vysker commented Dec 15, 2016

A lot of users are reporting that this extension does not work with PHP CS Fixer 2.0.x. So this issue will be here to accumulate as much info about the problem at hand.

If you are running into this issue as well, please post the following info:

  • OS.
  • VSCode version.
  • PHP CS Fixer version.
  • PHPFormatter version.
  • PHPFormatter user settings.
  • PHPFormatter logging output (use phpformatter.logging: true).
  • If possible, a snippet or screenshot of the code that needs formatting.

I will try to work out a solution soon enough. Time might be an issue around all the upcoming festivities, however.

Thanks!

@vysker vysker mentioned this issue Dec 15, 2016
@vysker vysker self-assigned this Dec 15, 2016
@vysker vysker added the bug label Dec 15, 2016
@Join-Git-Hub
Copy link

Join-Git-Hub commented Dec 15, 2016

OK, Thanks, here are my current Settings ✏️

OS.

Windows 7 Home Premium

VSCode version.

Version 1.8.0

PHP CS Fixer version.

2.0.0

PHPFormatter version

0.2.4

PHPFormatter user settings.

{
    "window.zoomLevel": 1.5,
    "editor.lineHeight": 28,
    "telemetry.enableTelemetry": false,
    "telemetry.enableCrashReporter": false,
    "php.validate.executablePath": "c:/xampp/php/php.exe",
    "phpformatter.phpPath": "C:/xampp/php/php.exe",
    "phpformatter.pharPath": "c:/xampp/php/php-cs-fixer.phar",
    "phpformatter.logging": true
}

PHPFormatter logging output (use phpformatter.logging: true).

log

If possible, a snippet or screenshot of the code that needs formatting.

class ControllerErrorPermission extends Controller {
	public function index() {
		$this->load->language('error/permission');

		$this->document->setTitle($this->language->get('heading_title'));

		$data['heading_title'] = $this->language->get('heading_title');

		$data['text_permission'] = $this->language->get('text_permission');

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('heading_title'),
			'href' => $this->url->link('error/permission', 'token=' . $this->session->data['token'], 'SSL')
		);

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('error/permission.tpl', $data));
	}

	public function check() {
		if (isset($this->request->get['route'])) {
			$route = '';

			$part = explode('/', $this->request->get['route']);

			if (isset($part[0])) {
				$route .= $part[0];
			}

			if (isset($part[1])) {
				$route .= '/' . $part[1];
			}

			$ignore = array(
				'common/dashboard',
				'common/login',
				'common/logout',
				'common/forgotten',
				'common/reset',
				'error/not_found',
				'error/permission',
				'dashboard/order',
				'dashboard/sale',
				'dashboard/customer',
				'dashboard/online',
				'dashboard/map',
				'dashboard/activity',
				'dashboard/chart',
				'dashboard/recent'
			);

			if (!in_array($route, $ignore) && !$this->user->hasPermission('access', $route)) {
				return new Action('error/permission');
			}
		}
	}
}

@sergiufp
Copy link

sergiufp commented Dec 15, 2016

I am experiencing a similar error:

PHPFormatter: Full command being executed: "E:\Web\UwAmp\bin\php\php-7.1.0-Win32-VC14-x86\php.exe" "E:\Web\UwAmp\bin\php\php-7.1.0-Win32-VC14-x86\phpcs.phar" fix "C:\Users\sergi\AppData\Local\Temp\phpfmt-7716K5NoyoCpqMqO.tmp" --level=psr2
PHPFormatter: Logging PHP-CS-Fixer command stdout result
PHPFormatter: ERROR: The file "fix" does not exist.

OS: Windows 10 Pro x64
VSCode version: 1.7.2
PHP CS Fixer version: 2.0.0
PHPFormatter version: 0.2.4
PHPFormatter user settings:

"phpformatter.pharPath": "E:\\Web\\UwAmp\\bin\\php\\php-7.1.0-Win32-VC14-x86\\phpcs.phar",
"phpformatter.phpPath": "E:\\Web\\UwAmp\\bin\\php\\php-7.1.0-Win32-VC14-x86\\php.exe",
"phpformatter.logging": true,

Later edit: issue persists after updating VSCode to version 1.8.0

@yaliv
Copy link

yaliv commented Dec 20, 2016

  • OS: Zorin OS 12 64-bit.
  • VSCode version: 1.8.1.
  • PHP CS Fixer version: 2.0.0.
  • PHPFormatter version: 0.2.4.
  • PHPFormatter user settings:
"phpformatter.composer": true,
"phpformatter.logging": true
  • PHPFormatter logging output: I don't know how to see the logging output.
  • My code snippets that needs formatting:
    public function actionItemDetail()
    {
        $title = Yii::$app->request->get('title');

                $data = $this->data();

                        $itemFound = null;

            foreach ($data as $d) {
            if ($d['title'] == $title) {
                $itemFound = $d;
                }
        }

                    return $this->render('itemDetail', ['title' => $title, 'itemFound' => $itemFound]);
    }

@Join-Git-Hub
Copy link

@yaliv

PHPFormatter logging output: I don't know how to see the logging output.

Klick HELP -> Toggle Developer Tool -> Console

@yaliv
Copy link

yaliv commented Dec 23, 2016

OK, here is the output in the console.

(I use the same versions as here).

Using Composer:

[Extension Host] PHPFormatter: Creating temp file.
[Extension Host] PHPFormatter: Tempfile fd: 61
[Extension Host] PHPFormatter: Tempfile name: /tmp/phpfmt-5947C8m6dUBQqw4n.tmp
[Extension Host] PHPFormatter: Writing current document content to temp file. Until VSCode will have a way of querying encoding, utf8 will be used for reading and writing.
[Extension Host] PHPFormatter: Full command being executed: php-cs-fixer fix "/tmp/phpfmt-5947C8m6dUBQqw4n.tmp" --level=psr2
[Extension Host] PHPFormatter: Logging PHP-CS-Fixer command stderr result
[Extension Host] PHPFormatter: 

  [Symfony\Component\Console\Exception\RuntimeException]
  The "--level" option does not exist.

fix [--path-mode PATH-MODE] [--allow-risky ALLOW-RISKY] [--config CONFIG] [--dry-run] [--rules RULES] [--using-cache USING-CACHE] [--cache-file CACHE-FILE] [--diff] [--format FORMAT] [--] [<path>]...

[Extension Host] PHPFormatter: Reading temp file content.
[Extension Host] PHPFormatter: Replacing editor content with formatted code.
[Extension Host] PHPFormatter: Document successfully formatted (19 lines).

Using php-cs-fixer.phar file:

[Extension Host] PHPFormatter: Creating temp file.
[Extension Host] PHPFormatter: Tempfile fd: 61
[Extension Host] PHPFormatter: Tempfile name: /tmp/phpfmt-5947Q0cGP1CpJXtR.tmp
[Extension Host] PHPFormatter: Writing current document content to temp file. Until VSCode will have a way of querying encoding, utf8 will be used for reading and writing.
[Extension Host] PHPFormatter: Full command being executed: "/opt/lampp/bin/php" "$HOME/phar/php-cs-fixer.phar" fix "/tmp/phpfmt-5947Q0cGP1CpJXtR.tmp" --level=psr2
[Extension Host] PHPFormatter: Logging PHP-CS-Fixer command stderr result
[Extension Host] PHPFormatter: 

  [RuntimeException]
  The "--level" option does not exist.

fix [--path-mode="..."] [--allow-risky="..."] [--config="..."] [--dry-run] [--rules="..."] [--using-cache="..."] [--cache-file="..."] [--diff] [--format="..."] [path1] ... [pathN]



[Extension Host] PHPFormatter: Reading temp file content.
[Extension Host] PHPFormatter: Replacing editor content with formatted code.
[Extension Host] PHPFormatter: Document successfully formatted (19 lines).

Sample case:
I copied a code snippet from a PDF document into VS Code, the code was copied without indentation. After trying to use PHPFormatter to format my code, nothing changed.

My code snippet:

<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\Room;
class RoomsController extends Controller
{
public function actionCreate()
{
$model = new Room();
$modelCanSave = false;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$modelCanSave = true;
}return $this->render('create', [
'model' => $model,
'modelSaved' => $modelCanSave
]);
}
}

@ncwgf
Copy link

ncwgf commented Dec 25, 2016

@yaliv
According to readme of php-cs-fixer https://github.com/FriendsOfPHP/PHP-CS-Fixer#usage
php php-cs-fixer.phar fix /path/to/project --rules=@PSR2
--level should be change to --rules=@psr2

and this extension will add --level=2 by default in setting phpformatter.arguments

just found it was discussed at #13

@yaliv
Copy link

yaliv commented Dec 26, 2016

@ncwgf

OK, it works with --rules argument.

Using @PSR2:

<?php
namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\Room;

class RoomsController extends Controller
{
    public function actionCreate()
    {
        $model = new Room();
        $modelCanSave = false;
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            $modelCanSave = true;
        }
        return $this->render('create', [
'model' => $model,
'modelSaved' => $modelCanSave
]);
    }
}

Using @Symfony:

<?php

namespace app\controllers;

use Yii;
use yii\web\Controller;
use app\models\Room;

class RoomsController extends Controller
{
    public function actionCreate()
    {
        $model = new Room();
        $modelCanSave = false;
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            $modelCanSave = true;
        }

        return $this->render('create', [
'model' => $model,
'modelSaved' => $modelCanSave,
]);
    }
}

The most difficult to format is the indentation for multi-line array. Any solution?

@ncwgf
Copy link

ncwgf commented Dec 26, 2016

it's php-cs-fixer problem and seem it still not ... ready
PHP-CS-Fixer/PHP-CS-Fixer#1438

@NewFuture
Copy link

@vysker
Copy link
Owner Author

vysker commented Jan 2, 2017

Thank you all for reporting in. I have been struggling with maintaining support for both versions of PHP CS Fixer for a while now. So in a next update I will be integrating PHP CS Fixer 2.0.0 to circumvent all this.

I will be leaving this issue open so people will have a place to go in the mean time.

@lichnow
Copy link

lichnow commented Jan 16, 2017

[Symfony\Component\Filesystem\Exception\IOException]
Failed to write file ".php_cs.cache", "no reason available".

My setting
{
"phpcs.standard": "PSR2",
"phpformatter.phpPath": "/usr/local/bin/php",
"phpformatter.composer": true,
"phpformatter.logging": true,
"phpformatter.arguments": [
"--rules=@psr2"
]
}

error

@ajkopinga
Copy link

@lichnow

I encountered the same 'Failed to write file ".php_cs.cache"' error. Caching only seems useful when fixing multiple files at once, so I skipped caching by adding '--using-cache false' to the phpformatter.arguments setting.

This is a temporary fix to make the formatter work.

@kadevland
Copy link

ai can't wowrking at all this extention

@kadevland
Copy link

when a save the file with debuug on i have "spawn php EMFILE"

@kadevland
Copy link

for me i have change addon.
So it's done for me

@lesydat
Copy link

lesydat commented Mar 22, 2017

I changed this setting from default value

  "phpformatter.arguments": [
    "--level=psr2"
  ],

to this

"phpformatter.arguments": []

It work well

@elisecode247
Copy link

@lesydat's solution worked for me.

@Tommixoft
Copy link

Tried every possible solution - nothing helps. I call this extension bullshit.
If it's not compatible with v2 - so write that in documentation.

@nucklearproject
Copy link

@lesydat
Work fine now...

@dxkite
Copy link

dxkite commented Jun 1, 2017

change argument --rules=@psr2 to --rules=@PSR2 will work well.
this is my setting

{
    "phpformatter.composer": true,
    "phpformatter.logging": true,
    "phpformatter.arguments": ["--rules=@PSR2"]
 }

@lesydat

@bardware
Copy link

"--level=psr2"

"--rules=@PSR2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests