A composer package for bloodtypes (website is in the gui branch)
composer require commandstring/blood
You can either create a blood object with proteins, antibodies, or type
use CommandString\Blood\Blood;
use CommandString\Blood\Enums\BloodType;
use CommandString\Blood\Enums\Protein;
$bloodFromType = new Blood(BloodType::A_POSITIVE);
$bloodFromProteins = Blood::fromProteins(Protein::A, Protein::RH);
$bloodFromAntibodies = Blood::fromAntibodies(Antibody::B, Antibody::RH);
use CommandString\Blood\Blood;
use CommandString\Blood\Enums\BloodType;
use CommandString\Blood\Enums\Protein;
$bloodType1 = new Blood(BloodType::A_POSITIVE);
$bloodType2 = new Blood(BloodType::O_NEGATIVE);
$bloodType1->canDonateTo($bloodType2); // false
$bloodType1->canReceiveFrom($bloodType2); // true
$bloodType2->canDonateTo($bloodType1); // true
$bloodType2->canReceiveFrom($bloodType1); // false
use CommandString\Blood\Enums\Protein;
/**
* @var \CommandString\Blood\Blood $bloodType1
* @var Protein[] $proteins
* @var Protein[] $antibodies
*/
$proteins = $bloodType1->getProteins();
$antibodies = $bloodType1->getAntibodies();
use CommandString\Blood\Enums\BloodType;
/**
* @var \CommandString\Blood\Blood $bloodType1
* @var BloodType $type
*/
$type = $bloodType1->getType();
$type = $bloodType1->type;
<?php
use CommandString\Blood\Blood;
use CommandString\Blood\Enums\BloodType;
require_once __DIR__ . '/vendor/autoload.php';
const ITEM_PREFIX = "* ";
const H2 = "\n## ";
const H3 = "\n### ";
$forType = static function (BloodType $type): void {
$blood = new Blood($type);
echo H2 . "Blood Type: {$blood->getType()->value}\n"; // A+
echo H3 . "Proteins:\n";
foreach ($blood->getProteins() as $protein) {
echo ITEM_PREFIX . "{$protein->value}\n";
}
echo H3 . "Antibodies:\n";
foreach ($blood->getAntibodies() as $antibody) {
echo ITEM_PREFIX . "{$antibody->value}\n";
}
echo H3. "Can Donate To:\n";
foreach (BloodType::cases() as $type) {
$toReceive = new Blood($type);
echo $blood->canDonateTo($toReceive) ? ITEM_PREFIX . "{$toReceive->getType()->value}\n" : '';
}
echo H3 . "Can Receive From:\n";
foreach (BloodType::cases() as $type) {
$toDonate = new Blood($type);
echo $blood->canReceiveFrom($toDonate) ? ITEM_PREFIX . "{$toDonate->getType()->value}\n" : '';
}
};
$divider = "---\n";
foreach (BloodType::cases() as $type) {
$forType($type);
echo $divider;
}
- A
- B
- RH
- A-
- A+
- AB-
- AB+
- A-
- A+
- AB-
- AB+
- A
- RH
- B
- A+
- AB+
- A+
- AB+
- B
- A
- RH
- B-
- B+
- AB-
- AB+
- B-
- B+
- AB-
- AB+
- B
- RH
- A
- B+
- AB+
- B+
- AB+
- A
- B
- RH
- AB-
- AB+
- AB-
- AB+
- A
- B
- RH
- AB+
- AB+
- A
- B
- RH
- A-
- A+
- B-
- B+
- AB-
- AB+
- O-
- O+
- A-
- A+
- B-
- B+
- AB-
- AB+
- O-
- O+
- RH
- A
- B
- A+
- B+
- AB+
- O+
- A+
- B+
- AB+
- O+