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

Class "Money\Money\Currency" does not exist #554

Open
dejagersh opened this issue Sep 2, 2024 · 7 comments · May be fixed by #555
Open

Class "Money\Money\Currency" does not exist #554

dejagersh opened this issue Sep 2, 2024 · 7 comments · May be fixed by #555

Comments

@dejagersh
Copy link

Hi, maybe I am doing something wrong but I get the following error:

Class "Money\Money\Currency" does not exist

reproducible example:

<?php

declare(strict_types=1);

use CuyZ\Valinor\Mapper\Source\Source;
use CuyZ\Valinor\MapperBuilder;
use Money\Currency;
use Money\Money;

require_once __DIR__ . '/vendor/autoload.php';

readonly class Transaction
{
    public Currency $currency;

    public string $amount;

    public function foobar(): Money
    {
        return new Money($this->amount, $this->currency);
    }
}

$mapper = (new MapperBuilder())
    ->allowSuperfluousKeys()
    ->mapper();

$mapper->map(
    Transaction::class,
    Source::array([
        'currency' => 'USD',
        'amount' => '100',
    ])
);

Any ideas on what I am doing wrong?

@romm
Copy link
Member

romm commented Sep 2, 2024

Hi @dejagersh, looks like a bug related to the Money\Money class. I'll have a look ASAP to fix this, and keep you updated here. 😊

@dejagersh
Copy link
Author

dejagersh commented Sep 2, 2024

Hi @dejagersh, looks like a bug related to the Money\Money class. I'll have a look ASAP to fix this, and keep you updated here. 😊

Thank you! Some extra context that might be useful: when I remove the foobar() method (and the Money\Money import), it works.

If I only remove the foobar() method, it doesn't work. So it has something to do with those imports I guess

@stof
Copy link

stof commented Sep 2, 2024

This looks like Valinor tries to use the use Money\Money use statement to resolve the class name of the use Money\Currency, as if Money\Currency was used as an unqualified name in the file. But use statements are always fully qualified (which is why we don't need a \ prefix in them).

@romm
Copy link
Member

romm commented Sep 2, 2024

Definitely a bug related to the use statements indeed.

@romm
Copy link
Member

romm commented Sep 2, 2024

@dejagersh could you checkout #555 and see if it solves your issue?

@dejagersh
Copy link
Author

dejagersh commented Sep 2, 2024

@dejagersh could you checkout #555 and see if it solves your issue?

Works like a charm!

image

Tested it both in the empty project that I used to make a reproducible example, and in my prod project and looks good ✅

@romm
Copy link
Member

romm commented Sep 18, 2024

Hi @dejagersh after @stof's comment I changed the code. As it is a major change compared to what you tested, would you mind doing it again to check everything is alright?

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

Successfully merging a pull request may close this issue.

3 participants