Skip to content

Commit

Permalink
Merge pull request prettier#1 from czosel/php-prettier
Browse files Browse the repository at this point in the history
Class: Add support for abstract, final, extends, implements
  • Loading branch information
mgrip committed Dec 22, 2017
2 parents 8eaf579 + 319840e commit 513535e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
24 changes: 23 additions & 1 deletion src/printer-php.js
Expand Up @@ -309,7 +309,29 @@ function printStatement(node) {
switch (node.kind) {
case "class":
return concat([
group(concat(["class ", node.name, " {"])),
group(
concat([
node.isAbstract ? "abstract " : "",
node.isFinal ? "final " : "",
"class ",
node.name,
indent(
concat([
node.extends
? concat([line, "extends ", printNode(node.extends)])
: "",
node.implements
? concat([
line,
"implements ",
join(", ", node.implements.map(printNode))
])
: ""
])
),
" {"
])
),
hardline,
indent(
concat(node.body.map(child => concat([hardline, printNode(child)])))
Expand Down
24 changes: 21 additions & 3 deletions tests/php_class/__snapshots__/jsfmt.spec.js.snap
@@ -1,8 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`class.php 1`] = `
exports[`class.php - php-verify: class.php 1`] = `
<?php
class Foo {
class Foo extends Bar implements Baz, Buzz {
public $test;
function test() {
return "test";
}
}
abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResourceController implements TooMuchObjectOrientation, ThisIsMadness {
// variable doc
public $test;
public $other = 1;
Expand All @@ -26,7 +35,16 @@ class Foo {
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<?php
class Foo {
class Foo extends Bar implements Baz, Buzz {
public $test;
public function test() {
return 'test';
}
}
abstract class ReallyReallyReallyLongClassName
extends AbstractModelFactoryResourceController
implements TooMuchObjectOrientation, ThisIsMadness {
// variable doc
public $test;
Expand Down
11 changes: 10 additions & 1 deletion tests/php_class/class.php
@@ -1,5 +1,14 @@
<?php
class Foo {

class Foo extends Bar implements Baz, Buzz {
public $test;

function test() {
return "test";
}
}

abstract class ReallyReallyReallyLongClassName extends AbstractModelFactoryResourceController implements TooMuchObjectOrientation, ThisIsMadness {
// variable doc
public $test;
public $other = 1;
Expand Down

0 comments on commit 513535e

Please sign in to comment.