class MyClass {
constructor(collaborator) {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {UnusualSpendingDetector} from "../src/UnusualSpendingDetector"; | |
describe('UnusualSpendingDetector', () => { | |
const currentMonth = '2020-02'; | |
const previousMonth = '2020-01'; | |
const userId = '1234'; | |
let paymentsRepository; | |
let detector; | |
beforeEach(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Rachel M. Carmena's https://github.com/rachelcarmena/code-smells | |
import java.util.Vector; // https://docs.oracle.com/javase/8/docs/api/java/util/Vector.html | |
public class CoolStack extends Vector { | |
public void push(Object element) { | |
insertElementAt(element, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Rachel M. Carmena's https://github.com/rachelcarmena/code-smells | |
public class DistanceCalculator { | |
public double betweenPoints(int x1, int y1, int x2, int y2) { | |
return Math.sqrt(Math.pow((y2 - y1), 2) + Math.pow(x2 - x1, 2)); | |
} | |
public double toOriginFrom(int x, int y) { | |
return Math.sqrt(Math.pow(y, 2) + Math.pow(x, 2)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Manager { | |
Worker $worker; | |
// some functions | |
public function doThing() : void { | |
$this->worker->doThing(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// As a direct chain of calls | |
class FlightBooking { | |
// ... | |
public function isSeatAvailable(int $rowNumber, string $seat) : boolean { | |
return $this->plane->getRow($rowNumber)->isAvailable($seat); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from Ayush Jindal's exercises for code smells https://github.com/ayjindal/CodeSmells | |
<?php | |
class Address { | |
private string $addressLine1; | |
private string $addressLine2; | |
private string $city; | |
private string $state; | |
private string $country; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from Rachel M. Carmena's https://github.com/rachelcarmena/code-smells | |
// see also Ds\Vector in https://www.php.net/manual/en/class.ds-vector.php | |
<?php | |
class CoolStack extends Ds\Vector { | |
public function push(...$values): void { | |
parent::push(...$values); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from Rachel M. Carmena's https://github.com/rachelcarmena/code-smells | |
<?php | |
class DistanceCalculator { | |
public function betweenPoints(int $x1, int $y1, int $x2, int $y2) : float { | |
return sqrt(pow(($y2 - $y1), 2) + pow($x2 - $x1, 2)); | |
} | |
public function toOriginFrom(int $x, int $y) : float { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Fixing Object oriented abusers, Manh Phan https://ducmanhphan.github.io/2020-01-24-Fixing-object-oriented-abusers/ | |
<?php | |
class CheckoutHandlder { | |
// ... | |
public function convertToCurrency(float $price, string $currencyTo) : float { | |
if ($currencyTo === "EUR") { | |
return $price * 0.9; |