Skip to content

Using UnitMap to add a unit HeadCount can't find unit #13

Description

@slavensaka

Hi im having a hard time figuring out why i get a not found.
I'm trying to add a Headcount.php unit within Amount unit type.
But i get this
Class 'PhpUnitConversion\Unit\Amount\HeadCount' not found

I'm using the UnitMap::add

UnitMap::add(
dirname(__DIR__, 2) .'/helpers/unitconversion/Fixtures/Amount/HeadCount.php',
 "PhpUnitConversion\\Unit",
\PhpUnitConversion\Unit\Amount::class
);

First parameter is the server path that's the correct path to my HeadCount.php
Second im not sure what to use
Third the class of the unit type I want to add it to

This is my HeadCount.php unit

 namespace PhpUnitConversion\Unit\Amount;
 use PhpUnitConversion\Unit\Amount;
 class HeadCount extends Amount
 {
   const FACTOR = 1;
  const SYMBOL = 'hc';
  const LABEL = 'head count';
}

Initlization:

$hd = new  \PhpUnitConversion\Unit\Amount\HeadCount(343);

I need to initilize it like above reason i have dynamic way of calling it

$convertFromClass = "\PhpUnitConversion\Unit\\". $type . "\\" .  $from;
$convertFrom = new $convertFromClass($formattedNumber);

Looking in Map.php source code the static load() adds it to self:$paths like this

"[["/var/www/vhost/biome/vendor/php-unit-conversion/php-unit-conversion/src/Unit/"
"PhpUnitConversion\Unit"
true
null]

["/var/www/vhost/biome/app/helpers/unitconversion/Fixtures/Amount/HeadCount.php"
"PhpUnitConversion\Unit"
true
"PhpUnitConversion\Unit\Amount"]]"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions