Skip to content
Permalink
Browse files

MultilineCommentOpeningClosingAloneFixer - fix for changing comment t…

…o PHPDoc (#179)
  • Loading branch information
kubawerlos committed Nov 10, 2019
1 parent beb9c53 commit 379b6bb4ea0191e9c533d1bbcbfa564d75278460
@@ -8,7 +8,7 @@

[![Build status](https://img.shields.io/travis/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://travis-ci.org/kubawerlos/php-cs-fixer-custom-fixers)
[![Code coverage](https://img.shields.io/coveralls/github/kubawerlos/php-cs-fixer-custom-fixers/master.svg)](https://coveralls.io/github/kubawerlos/php-cs-fixer-custom-fixers?branch=master)
![Tests](https://img.shields.io/badge/tests-1360-brightgreen.svg)
![Tests](https://img.shields.io/badge/tests-1365-brightgreen.svg)
[![Mutation testing badge](https://badge.stryker-mutator.io/github.com/kubawerlos/php-cs-fixer-custom-fixers/master)](https://stryker-mutator.github.io)
[![Psalm type coverage](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers/coverage.svg)](https://shepherd.dev/github/kubawerlos/php-cs-fixer-custom-fixers)

@@ -63,21 +63,21 @@ private function fixOpening(Tokens $tokens, int $index): void
}

Preg::match('#\R(\h*)#', $token->getContent(), $matches);
$indent = $matches[1];
$indent = $matches[1] . '*';

Preg::match('#^(/\*+)(.*?)(\R)(.*)$#s', $token->getContent(), $matches);
Preg::match('#^(?<opening>/\*+)(?<before_newline>.*?)(?<newline>\R)(?<after_newline>.*)$#s', $token->getContent(), $matches);
if ($matches === []) {
return;
}

if ($matches[2][0] === '/') {
$matches[2] = ' ' . $matches[2];
if ($matches['before_newline'][0] !== ' ') {
$indent .= ' ';
}

$newContent = $matches[1] . $matches[3] . $indent . '*' . $matches[2] . $matches[3] . $matches[4];
$newContent = $matches['opening'] . $matches['newline'] . $indent . $matches['before_newline'] . $matches['newline'] . $matches['after_newline'];

if ($newContent !== $token->getContent()) {
$tokens[$index] = new Token([$token->getId(), $newContent]);
$tokens[$index] = new Token([Preg::match('~/\*{2}\s~', $newContent) === 1 ? T_DOC_COMMENT : T_COMMENT, $newContent]);
}
}

@@ -37,27 +37,50 @@ public function testFix(string $expected, ?string $input = null): void

public function provideFixCases(): iterable
{
yield ['<?php /* Foo */'];
yield ['<?php /** Foo */'];

yield ['<?php /**
* Foo
*/'];

yield [
'<?php /* Foo */',
'<?php
/*
* Foo
*/',
'<?php
/* Foo
*/',
];

yield [
'<?php /** Foo */',
'<?php
/*
* Foo
*/',
'<?php
/*Foo
*/',
];

yield [
'<?php /**
* Foo
*/',
'<?php
/*
* Foo
*/',
'<?php
/* Foo
*/',
];

yield [
'<?php
/*
/**
* Foo
*/',
'<?php
/* Foo
/** Foo
*/',
];

@@ -67,10 +90,20 @@ public function provideFixCases(): iterable
* Foo
*/',
'<?php
/** Foo
/**Foo
*/',
];

yield [
'<?php
/****
* Foo
****/',
'<?php
/**** Foo
****/',
];

yield [
'<?php
/*
@@ -91,6 +124,16 @@ public function provideFixCases(): iterable
* Foo */',
];

yield [
'<?php
/**
* Foo
*/',
'<?php
/**
* Foo*/',
];

yield [
\str_replace("\n", "\r", '<?php
/**

0 comments on commit 379b6bb

Please sign in to comment.
You can’t perform that action at this time.