/** * @param ZoneInterface $zone * @param CountryInterface $country * * @return boolean Country is contained in zone */ public function isCountryContainedInZone(ZoneInterface $zone, CountryInterface $country) { return $zone->getMembers()->filter(function (ZoneMemberInterface $zoneMember) { return $zoneMember instanceof ZoneCountryMemberInterface; })->exists(function ($_, ZoneCountryMemberInterface $zoneCountryMember) use($country) { return $country->equals($zoneCountryMember->getCountry()); }); }
/** * Get siblings * * @return Collection siblings */ public function getSiblings() { return $this->country->getStates(); }
/** * Return if a country is equal than current * * @param CountryInterface $country Country to be compared with * * @return boolean Countries are the same */ public function equals(CountryInterface $country) { return $country->getCode() === $this->getCode(); }
/** * Add state with the premise that the country has to be added already * * @param CountryInterface $country Country * @param string $stateCode State code * @param string $stateName State name * * @return StateInterface */ public function addState(CountryInterface $country, $stateCode, $stateName) { $stateCode = trim($stateCode); $stateName = trim($stateName); $stateId = $country->getCode() . '_' . $stateCode; if (!isset($this->states[$stateId])) { $state = $this->stateFactory->create(); $state->setId($stateId)->setCode($stateCode)->setName($stateName)->setCountry($country)->setProvinces(new ArrayCollection())->setEnabled(true); $country->addState($state); $this->states[$stateId] = $state; } return $this->states[$stateId]; }
/** * Test the provinces entities * * @param CountryInterface $country Country * * @return $this Self Object */ public function blockTestProvinces(CountryInterface $country) { $nbProvinces = 0; $nbCities = 0; $nbPostalCodes = 0; $country->getStates()->map(function (StateInterface $state) use(&$nbProvinces, &$nbCities, &$nbPostalCodes) { $provinces = $state->getProvinces(); $nbProvinces += $provinces->count(); $provinces->map(function (ProvinceInterface $province) use(&$nbCities, &$nbPostalCodes) { $cities = $province->getCities(); $nbCities += $cities->count(); $cities->map(function (CityInterface $city) use(&$nbPostalCodes) { $cityPostalCodes = $city->getPostalCodes(); $nbPostalCodes += $cityPostalCodes->count(); }); }); }); $this->assertEquals(98, $nbProvinces); $this->assertEquals(36631, $nbCities); $this->assertEquals(20414, $nbPostalCodes); return $this; }