-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for inheritance in #[Friend] #29
Comments
The original design was for friends to specify the exact class, however your suggestion makes a lot of sense, so I will look to get this implemented. |
@alek-as have you got a more real life example you'd be happy to share? Having something real, rather than abstract will probably help me implement the correct thing. @alek-as (cc @TomAdam) Thanks |
In our case, the <?php
declare(strict_types=1);
namespace App;
use DaveLiddament\PhpLanguageExtensions\Friend;
interface Invoice
{
}
class InvoiceLine
{
#[Friend(Invoice::class)]
public function changeAmount(int $newAmount): void
{
}
}
class RegularInvoice implements Invoice
{
/**
* @var array<InvoiceLine>
*/
private array $invoiceLines;
public function changeInvoiceLineAmount(InvoiceLine $line, int $newAmount): void
{
// verify that the invoice line belongs to this invoice
// protect some invariants
$line->changeAmount($newAmount);
}
} The examples from PR look good, not sure if adding another one is necessary (I'd assume above case will also be covered now) |
The library works very well for most of our use cases, thank you for creating it!
We've recently discovered that adding
#[Friend]
annotation with an interface as friend class will produce an error when the method is called from implementation classes.See below for simple code snippet:
Produced error:
Is this error intentional?
The text was updated successfully, but these errors were encountered: