Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Equine;
- class HeadDna {
- public const HEAD_CONVEX = 'cvx';
- public const HEAD_STRAIGHT = 'str';
- public const HEAD_CONCAVE = 'ccv';
- protected array $lower = [
- self::HEAD_STRAIGHT,
- self::HEAD_STRAIGHT
- ];
- protected array $middle = [
- self::HEAD_STRAIGHT,
- self::HEAD_STRAIGHT
- ];
- protected array $higher = [
- self::HEAD_STRAIGHT,
- self::HEAD_STRAIGHT
- ];
- public function getLower() : array {
- return $this->lower;
- }
- public function getMiddle() : array {
- return $this->middle;
- }
- public function getHigher() : array {
- return $this->higher;
- }
- private function getActiveGene(array $allele) : string
- {
- if (in_array(self::HEAD_CONVEX, $allele)) {
- return self::HEAD_CONVEX;
- }
- if (in_array(self::HEAD_STRAIGHT, $allele)) {
- return self::HEAD_STRAIGHT;
- }
- return self::HEAD_CONCAVE;
- }
- public function getActiveGenes() : array
- {
- return [
- 'lower' => $this->getActiveGene($this->lower),
- 'middle' => $this->getActiveGene($this->middle),
- 'higher' => $this->getActiveGene($this->higher)
- ];
- }
- public function getActiveGeneOccurances() : array
- {
- $occurances = array_count_values($this->getActiveGenes());
- return [
- self::HEAD_CONVEX => $occurances[self::HEAD_CONVEX] ?? 0,
- self::HEAD_STRAIGHT => $occurances[self::HEAD_STRAIGHT] ?? 0,
- self::HEAD_CONCAVE => $occurances[self::HEAD_CONCAVE] ?? 0
- ];
- }
- public function setAllAlleles(array $alleles) : void
- {
- $this->lower = $alleles['lower'];
- $this->middle = $alleles['middle'];
- $this->higher = $alleles['higher'];
- }
- public function getAllAlleles() : array
- {
- return [
- 'lower' => $this->lower,
- 'middle' => $this->middle,
- 'higher' => $this->higher
- ];
- }
- public function importJson(array $jsonDna) : void
- {
- $this->lower = json_decode($jsonDna['lower']);
- $this->middle = json_decode($jsonDna['middle']);
- $this->higher = json_decode($jsonDna['higher']);
- }
- public function exportJson() : array
- {
- return [
- 'lower' => json_encode($this->lower),
- 'middle' => json_encode($this->middle),
- 'higher' => json_encode($this->higher)
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement