Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion src/Impact/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,69 @@
self::IMPACT_EPT => 'ept',
];

private static array $impact_categorization = [

Check failure on line 88 in src/Impact/Type.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.5 - mariadb:11.8 / Continuous integration

Static property GlpiPlugin\Carbon\Impact\Type::$impact_categorization is never read, only written.

Check failure on line 88 in src/Impact/Type.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Static property GlpiPlugin\Carbon\Impact\Type::$impact_categorization is never read, only written.
'Acidification' => [
'ap',
], 'Climate change' => [
'gwp',
], 'Ecotoxicity, freshwater' => [
'ctue',
], 'EF-particulate matter' => [
'pm',
], 'Eutrophication, freshwater' => [
'epf',
], 'Eutrophication, marine' => [
'epm',
], 'Eutrophication, terrestrial' => [
'ept',
], 'Human toxicity, cancer' => [
'ctuh_c',
], 'Human toxicity, non-cancer' => [
'ctuh_nc',
], 'Ionising radiation' => [
'ir',
], 'Land use' => [
'lu',
], 'Ozone depletion' => [
'odp',
], 'Photochemical ozone formation' => [
'pocp',
], 'Resource depletion, fossils' => [
'adpf',
], 'Resource depletion, minerals and metals' => [
'adp',
], 'Water use' => [
'wu',
],
];

/**
* Impact weight factor
* Sum must be equal to 100%
* @see https://eplca.jrc.ec.europa.eu/permalink/EF3_1/Normalisation_Weighting_Factors_EF_3.1.xlsx
* @see Source: Sala S, Cerutti AK, Pant R. (2018). Development of a weighting approach for Environmental Footprint. European Commission, Joint Research Centre, Publication Office of the European Union, Luxembourg. ISBN 978-92-79-68041-0.
*
* @var array<string, float>
*/
private static array $category_weight_percentage = [

Check failure on line 132 in src/Impact/Type.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.5 - mariadb:11.8 / Continuous integration

Static property GlpiPlugin\Carbon\Impact\Type::$category_weight_percentage is never read, only written.

Check failure on line 132 in src/Impact/Type.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Static property GlpiPlugin\Carbon\Impact\Type::$category_weight_percentage is never read, only written.
'Acidification' => 6.20,
'Climate change' => 21.06,
'Ecotoxicity, freshwater' => 1.92,
'EF-particulate matter' => 8.96,
'Eutrophication, freshwater' => 2.80,
'Eutrophication, marine' => 2.96,
'Eutrophication, terrestrial' => 3.71,
'Human toxicity, cancer' => 2.13,
'Human toxicity, non-cancer' => 1.84,
'Ionising radiation' => 5.01,
'Land use' => 7.94,
'Ozone depletion' => 6.31,
'Photochemical ozone formation' => 4.78,
'Resource depletion, fossils' => 8.32,
'Resource depletion, minerals and metals' => 7.55,
'Water use' => 8.51,
];

/**
* Unit of impact criterias
*
Expand All @@ -101,7 +164,7 @@
'lu' => null,
'odp' => ['g', 'CFC-11 eq'],
'pm' => null,
'pocp' => ['g', 'U235 eq'],
'pocp' => ['g', 'NMVOC eq'],
'wu' => ['m³', ''],
'mips' => ['g', ''],
'adpe' => ['g', 'SB eq'],
Expand Down Expand Up @@ -401,4 +464,5 @@

return '';
}

}
55 changes: 55 additions & 0 deletions tests/units/Impact/TypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/**
* -------------------------------------------------------------------------
* Carbon plugin for GLPI
*
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
* @copyright Copyright (C) 2024 by the carbon plugin team.
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
* @link https://github.com/pluginsGLPI/carbon
*
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Carbon plugin for GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/

namespace GlpiPlugin\Carbon\Impact\Tests;

use GlpiPlugin\Carbon\Impact\Type;
use GlpiPlugin\Carbon\Tests\DbTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionClass;

#[CoversClass(Type::class)]
class TypeTest extends DbTestCase
{
public function test_category_weight_percentage_sum_equals_100_percent(): void
{
$reflection = new ReflectionClass(Type::class);
$property = $reflection->getProperty('category_weight_percentage');
// $property->setAccessible(true);
$weights = $property->getValue();

$sum = array_sum($weights);

$this->assertEquals(100.0, $sum);
}
}
Loading