You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+8-16
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
As this package is still very much a work in progress, any help adding more unit's and unit tests is really appreciated!
3
3
4
4
A couple of things are important when submitting a Pull Request:
5
-
- Use the PSR-2 Coding Standard
5
+
- Use PSR-2 Coding Standard
6
6
- Add tests
7
7
- Use the method of implementation as described below
8
8
@@ -25,23 +25,15 @@ imperial / usc systems.
25
25
Now create a folder `Unit/XXX/` in which we will place all the unit classes for this unit type, after this proceed with adding a base unit
26
26
27
27
#### Adding a base unit
28
-
We prefer the base unit to be a unit from the metric system. This way we can easily add all SI prefixed units by extending them from the base
29
-
unit and only implement a `PhpUnitConversion\Prefix\Metric\<SI_Prefix>` interface. E.g. the implementation of `Mass\MilliGram` is:
30
-
```php
31
-
class MilliGram extends Gram implements Metric, Milli
32
-
{}
33
-
```
34
-
You should not set a `FACTOR` on the `BASE_UNIT`, otherwise the above implementation will fail because the interface `Prefix\Metric\Milli`
35
-
cannot overwrite an already defined class constant.
36
-
37
-
See `Gruntfile.js` for a quick way to add all prefixed classes to your unit.
28
+
We prefer the base unit to be a unit from the SI and/or metric system. If your unit should use the SI prefixes, please use the `Gruntfile.js` for a
29
+
quick way to add all prefixed classes to your unit.
38
30
39
31
#### Add an new unit to a unit type
40
32
When adding a unit `YYY` to unit type `XXX` start by creating the file `Unit/XXX/YYY.php`.
41
33
42
34
If your unit has a linear correspondence to the base unit, just set the class constant `FACTOR` to its correct value.
43
-
If your unit has an offset to the base unit, you can add a class constant `ADDITION`.
44
-
(Conversion to the BASE_UNIT value is done by first applying the `FACTOR`, then adding the `ADDITION`)
35
+
If your unit has an offset to the base unit, you can add a class constant `ADDITION_PRE` or `ADDITION_POST`.
36
+
These correspond to the following formula: `BaseUnitValue = (ThisUnitValue + ADDITION_PRE) * FACTOR + ADDITION_POST`
45
37
46
38
Please also set the class constant `SYMBOL` and `LABEL`. When your unit does not have a `SYMBOL`, omit it or set it to an empty string. `LABEL` is often equal to your lower case classname.
47
39
@@ -56,14 +48,14 @@ class AvoirdupoisPound extends Mass
56
48
{
57
49
use HasFactor;
58
50
59
-
const FACTOR = 453.59237; // FACTOR is relative to Mass\Gram, 453.6 Gram in a Pound
51
+
const FACTOR = 453.59237; // FACTOR is relative to Mass\Gram, 1 Avoirdupois Pound is 453.6 Gram
60
52
}
61
53
62
54
class Ounce extends Pound
63
55
{
64
56
use HasRelativeFactor;
65
57
66
-
const FACTOR = 16; // FACTOR is relative to Mass\Pound, 16 Ounce in a Pound
58
+
const FACTOR = 1/16; // FACTOR is relative to Mass\Pound, 1 Ounce is 1/16 Pound (or 16 Ounce in a Pound)
0 commit comments