-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Modernize documentation code #10126
Merged
Merged
Modernize documentation code #10126
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,48 +23,32 @@ concrete subclasses, ``ConcreteComponent`` and ``ConcreteDecorator``. | |
|
||
namespace Test; | ||
|
||
/** | ||
* @Entity | ||
* @InheritanceType("SINGLE_TABLE") | ||
* @DiscriminatorColumn(name="discr", type="string") | ||
* @DiscriminatorMap({"cc" = "Test\Component\ConcreteComponent", | ||
"cd" = "Test\Decorator\ConcreteDecorator"}) | ||
*/ | ||
#[Entity] | ||
#[InheritanceType('SINGLE_TABLE')] | ||
#[DiscriminatorColumn(name: 'discr', type: 'string')] | ||
#[DiscriminatorMap(['cc' => Component\ConcreteComponent::class, | ||
'cd' => Decorator\ConcreteDecorator::class])] | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See discussion here slevomat/coding-standard#1456 |
||
abstract class Component | ||
{ | ||
|
||
/** | ||
* @Id @Column(type="integer") | ||
* @GeneratedValue(strategy="AUTO") | ||
*/ | ||
protected $id; | ||
#[Id, Column] | ||
#[GeneratedValue(strategy: 'AUTO')] | ||
protected int|null $id = null; | ||
|
||
/** @Column(type="string", nullable=true) */ | ||
#[Column(type: 'string', nullable: true)] | ||
protected $name; | ||
|
||
/** | ||
* Get id | ||
* @return integer $id | ||
*/ | ||
public function getId() | ||
public function getId(): int|null | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* Set name | ||
* @param string $name | ||
*/ | ||
public function setName($name) | ||
public function setName(string $name): void | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* Get name | ||
* @return string $name | ||
*/ | ||
public function getName() | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
@@ -86,7 +70,7 @@ purpose of keeping this example simple). | |
|
||
use Test\Component; | ||
|
||
/** @Entity */ | ||
#[Entity] | ||
class ConcreteComponent extends Component | ||
{} | ||
|
||
|
@@ -103,14 +87,11 @@ use a ``MappedSuperclass`` for this. | |
|
||
namespace Test; | ||
|
||
/** @MappedSuperclass */ | ||
#[MappedSuperclass] | ||
abstract class Decorator extends Component | ||
{ | ||
|
||
/** | ||
* @OneToOne(targetEntity="Test\Component", cascade={"all"}) | ||
* @JoinColumn(name="decorates", referencedColumnName="id") | ||
*/ | ||
#[OneToOne(targetEntity: Component::class, cascade: ['all'])] | ||
#[JoinColumn(name: 'decorates', referencedColumnName: 'id')] | ||
protected $decorates; | ||
|
||
/** | ||
|
@@ -126,25 +107,19 @@ use a ``MappedSuperclass`` for this. | |
* (non-PHPdoc) | ||
* @see Test.Component::getName() | ||
*/ | ||
public function getName() | ||
public function getName(): string | ||
{ | ||
return 'Decorated ' . $this->getDecorates()->getName(); | ||
} | ||
|
||
/** | ||
* the component being decorated | ||
* @return Component | ||
*/ | ||
protected function getDecorates() | ||
/** the component being decorated */ | ||
protected function getDecorates(): Component | ||
{ | ||
return $this->decorates; | ||
} | ||
|
||
/** | ||
* sets the component being decorated | ||
* @param Component $c | ||
*/ | ||
protected function setDecorates(Component $c) | ||
/** sets the component being decorated */ | ||
protected function setDecorates(Component $c): void | ||
{ | ||
$this->decorates = $c; | ||
} | ||
|
@@ -187,27 +162,19 @@ of the getSpecial() method to its return value. | |
|
||
use Test\Decorator; | ||
|
||
/** @Entity */ | ||
#[Entity] | ||
class ConcreteDecorator extends Decorator | ||
{ | ||
|
||
/** @Column(type="string", nullable=true) */ | ||
protected $special; | ||
#[Column(type: 'string', nullable: true)] | ||
protected string|null $special = null; | ||
|
||
/** | ||
* Set special | ||
* @param string $special | ||
*/ | ||
public function setSpecial($special) | ||
public function setSpecial(string|null $special): void | ||
{ | ||
$this->special = $special; | ||
} | ||
|
||
/** | ||
* Get special | ||
* @return string $special | ||
*/ | ||
public function getSpecial() | ||
public function getSpecial(): string|null | ||
{ | ||
return $this->special; | ||
} | ||
|
@@ -216,7 +183,7 @@ of the getSpecial() method to its return value. | |
* (non-PHPdoc) | ||
* @see Test.Component::getName() | ||
*/ | ||
public function getName() | ||
public function getName(): string | ||
{ | ||
return '[' . $this->getSpecial() | ||
. '] ' . parent::getName(); | ||
|
@@ -270,4 +237,3 @@ objects | |
|
||
echo $d->getName(); | ||
// prints: [Really] Decorated Test Component 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite the fact that branch is already merged: I personally prefer multiple attributes in single '#[...]' looks a bit cleaner ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was like that before 🤷