PHPackages                             shiptor/shipping-calculator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. shiptor/shipping-calculator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

shiptor/shipping-calculator
===========================

Shipping calculation library based on Symfony 2 components.

0.1.8(10y ago)53.5k4MITPHPPHP &gt;=5.4

Since Nov 5Pushed 10y ago3 watchersCompare

[ Source](https://github.com/esteit/shipping-calculator)[ Packagist](https://packagist.org/packages/shiptor/shipping-calculator)[ RSS](/packages/shiptor-shipping-calculator/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (9)Versions (19)Used By (0)

Shipping Calculator
===================

[](#shipping-calculator)

[![Build Status](https://camo.githubusercontent.com/c0f92e392a9478dd809c712dcdbcba2b408f17b7fc16b7fa9c155816c14d9593/68747470733a2f2f7472617669732d63692e6f72672f6573746569742f7368697070696e672d63616c63756c61746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/esteit/shipping-calculator)[![Test Coverage](https://camo.githubusercontent.com/bba0915c22e7947ada6d9801509cf2a386c63c39dcf5bc417a5aa02ddc6d4cda/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6573746569742f7368697070696e672d63616c63756c61746f722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/esteit/shipping-calculator/coverage)[![Code Climate](https://camo.githubusercontent.com/cf0645c0a0f1ba523d1b08d11b3381f66677b2f25db7a78b29794f6a9f1b01b9/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6573746569742f7368697070696e672d63616c63756c61746f722f6261646765732f6770612e737667)](https://codeclimate.com/github/esteit/shipping-calculator)[![Latest Stable Version](https://camo.githubusercontent.com/bb3844e6f305167903c4e30d4898537a8981650dc9171f0755f28bcb57d47e2c/68747470733a2f2f706f7365722e707567782e6f72672f73686970746f722f7368697070696e672d63616c63756c61746f722f762f737461626c65)](https://packagist.org/packages/shiptor/shipping-calculator)[![Total Downloads](https://camo.githubusercontent.com/8dde0fce883e1b45331fb899bfd7ffde09b3f1ce226b74b89197113e7c23fa3a/68747470733a2f2f706f7365722e707567782e6f72672f73686970746f722f7368697070696e672d63616c63756c61746f722f646f776e6c6f616473)](https://packagist.org/packages/shiptor/shipping-calculator)[![License](https://camo.githubusercontent.com/4b225ef1381649ecb118b23b26bf5a00558fdfb8b1764edce613904e2fbf2b4f/68747470733a2f2f706f7365722e707567782e6f72672f73686970746f722f7368697070696e672d63616c63756c61746f722f6c6963656e7365)](https://packagist.org/packages/shiptor/shipping-calculator)

Shipping calculation library based on Symfony 2 components.

Installation
------------

[](#installation)

Add in your `composer.json` the require entry for this library.

```
{
    "require": {
        "shiptor/shipping-calculator": "*"
    }
}
```

and run `composer install` (or `update`) to download all files.

Usage
-----

[](#usage)

### How to create a calculator?

[](#how-to-create-a-calculator)

Example code below will create the calculator for a single shipment method.

```
$config = include __DIR__.'/../src/Resources/DHL/ExportExpressWorldWide/tariff_2015_08_25_usa.php';
$calculator = new BaseCalculator([
    'handler' => DhlHandler::create($config)
]);
```

What is what:

- [DhlCalculatorHandler](/src/Calculator/BaseCalculator.php) contains calculation algorithm for the Dhl Express Shipping Method;
- [$config](/src/Resources/DHL/ExportExpressWorldWide/tariff_2015_08_25_usa.php) contains configuration for the `DhlHandler`;
- [BaseCalculator](/src/Calculator/BaseCalculator.php) is a wrapper for a calculation handlers, it contains an algorithm "How to use calculation handlers" and returns a calculation result;

### How to calculate a package shipping?

[](#how-to-calculate-a-package-shipping)

Example code below will create a package and calculate shipping cost for Dhl Express.

```
// previous example code here

$weight = new Weight();
$weight->setValue(10);
$weight->setUnit('lb');

$dimensions = new Dimensions();
$dimensions->setLength(10);
$dimensions->setWidth(10);
$dimensions->setHeight(10);
$dimensions->setUnit('in');

$senderAddress = new Address();
$senderAddress->setCountryCode('USA');

$recipientAddress = new Address();
$recipientAddress->setCountryCode('RUS');

$package = new Package();
$package->setWeight($weight);
$package->setDimensions($dimensions);
$package->setSenderAddress($senderAddress);
$package->setRecipientAddress($recipientAddress);

$result = $calculator->calculate($package);
```

What is what:

- [Weight](/src/Weight.php) contains information about physical weight;
- [Dimensions](/src/Dimensions.php) contains information about package box dimensions. It is required to calculate a volumetric weight of your package;
- [$senderAddress](/src/Address.php) and [$recipientAddress](/src/Address.php) contains information about sender and recipient;
- [Package](/src/Package.php) is a wrapper object to all objects above. You will need to pass this object to `calculate` method of your calculator;
- [$result](/src/Result.php) contains your package and resulting calculation data;

### How to extend a calculator?

[](#how-to-extend-a-calculator)

Shipping calculator uses [symfony event dispatcher](https://github.com/symfony/event-dispatcher) and you can use it to extend calculation algorithms as you need. For example, you can increase shipping cost by 10$.

```
// place calculator creation code here

$calculator->getDispatcher()->addListener(Events::AFTER_CALCULATE, function (AfterCalculateEvent $event) {
    $event->getResult()->setShippingCost($event->getResult()->getShippingCost() + 10);
});
```

What is what:

- `Events::AFTER_CALCULATE` is an event calling when calculation ends and calculation result is ready;
- `AfterCalculateEvent` is an event object which contains calculation result and package. Look to other available events [here](/src/Event);

### More ideas how to use and extend shipping calculator

[](#more-ideas-how-to-use-and-extend-shipping-calculator)

- create calculation handlers for other couriers and shipping methods;
- create calculators and realize your own algorithms using handlers;

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Recently: every ~12 days

Total

18

Last Release

3776d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fd9a799b87d152a1af81ff3093367b5d91771d6b9703ac9399730f1b14ebbedf?d=identicon)[moriony](/maintainers/moriony)

---

Top Contributors

[![moriony](https://avatars.githubusercontent.com/u/1702031?v=4)](https://github.com/moriony "moriony (83 commits)")[![sektor-sumy](https://avatars.githubusercontent.com/u/4012007?v=4)](https://github.com/sektor-sumy "sektor-sumy (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shiptor-shipping-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/shiptor-shipping-calculator/health.svg)](https://phpackages.com/packages/shiptor-shipping-calculator)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k185.6M2.4k](/packages/symfony-security-bundle)[phpro/grumphp

A composer plugin that enables source code quality checks.

4.3k16.7M1.0k](/packages/phpro-grumphp)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M507](/packages/pimcore-pimcore)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M576](/packages/shopware-core)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
